C Language: modf function
(Split into Integer and Fractional Parts)
In the C Programming Language, the modf function splits a floating-point value into an integer and a fractional part. The fraction is returned by the modf function and the integer part is stored in the iptr variable.
Syntax
The syntax for the modf function in the C Language is:
double modf(double value, double *iptr);
Parameters or Arguments
- value
- The floating-point value to split into an integer and a fractional part.
- iptr
- A pointer to a variable where the integer part will be stored.
Returns
The modf function returns the fractional part of value.
Required Header
In the C Language, the required header for the modf function is:
#include <math.h>
Applies To
In the C Language, the modf function can be used in the following versions:
- ANSI/ISO 9899-1990
modf Example
/* Example using modf by TechOnTheNet.com */ #include <stdio.h> #include <math.h> int main(int argc, const char * argv[]) { /* Define temporary variables */ double value; double i, f; /* Assign the value we will calculate the modf of */ value = 1.7; /* Calculate the modf of the value returning the fractional and integral parts */ f = modf(value, &i); /* Display the result of the calculation */ printf("The Integral and Fractional parts of %f are %f and %f\n", value, i, f); return 0; }
When compiled and run, this application will output:
The Integral and Fractional parts of 1.700000 are 1.000000 and 0.700000
Similar Functions
Other C functions that are similar to the modf function:
Advertisements