modf, _modfl

Description

Split a floating-point value into fractional and integer parts.

#include <math.h>

double modf( double x, double *intptr );

long double _modfl( long double x, long double *intptr );

x Floating-point value  
intptr Pointer to stored integer portion  

Remarks

The modf functions break down the floating-point value x into fractional and integer parts, each of which has the same sign as x. The signed fractional portion of x is returned. The integer portion is stored as a floating-point value at intptr.

The _modfl function uses the 80-bit, 10-byte coprocessor form of arguments and return values. See the reference page on the long double functions for more details on this data type.

Return Value

The modf and _modfl functions return the signed fractional portion of x. There is no error return.

Compatibility

modf

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

_modfl

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

See Also

frexp, ldexp

Example

/* MODF.C */

#include <math.h>

#include <stdio.h>

void main( void )

{

double x, y, n;

x = -14.87654321; /* Divide x into its fractional */

y = modf( x, &n ); /* and integer parts */

printf( "For %f, the fraction is %f and the integer is %.f\n", x, y, n );

}

Output

For -14.876543, the fraction is -0.876543 and the integer is -14