title | ms.custom | ms.date | ms.technology | ms.topic | apiname | apilocation | apitype | f1_keywords | dev_langs | helpviewer_keywords | ms.assetid | author | ms.author | ms.workload | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
modf, modff, modfl | Microsoft Docs |
04/05/2018 |
|
reference |
|
|
DLLExport |
|
|
|
b1c7abf5-d476-43ca-a03c-02072a86e32d |
corob-msft |
corob |
|
Splits a floating-point value into fractional and integer parts.
double modf( double x, double * intptr );
float modff( float x, float * intptr );
long double modfl( long double x, long double * intptr );
float modf( float x, float * intptr ); // C++ only
long double modf( long double x, long double * intptr ); // C++ only
x
Floating-point value.
intptr
Pointer to stored integer portion.
This function returns the signed fractional portion of x. There is no error return.
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.
modf has an implementation that uses Streaming SIMD Extensions 2 (SSE2). See _set_SSE2_enable for information and restrictions on using the SSE2 implementation.
C++ allows overloading, so you can call overloads of modf that take and return float or long double parameters. In a C program, modf always takes two double values and returns a double value.
Routine | Required header |
---|---|
modf, modff, modfl | C: <math.h> C++: , <cmath> or <math.h> |
For additional compatibility information, see Compatibility.
// crt_modf.c
#include <math.h>
#include <stdio.h>
int 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 );
}
For -14.876543, the fraction is -0.876543 and the integer is -14