modf、modff

拆分一个浮点值到整数部分和小数部分。

double modf( 
   double x, 
   double *intptr  
); 
float modf( 
   float x, 
   float *intptr 
);  // C++ only 
long double modf( 
   long double x, 
   long double * intptr 
);  // C++ only 
float modff( 
   float x, 
   float *intptr  
);

参数

  • x
    浮点值。

  • intptr
    对存储的整数部分的指针。

返回值

此函数返回 x 的有符号小数部分。 无错误返回。

备注

modf 函数将浮点值 x 拆分为整数部分和小数部分,其中每个都有和 x. 相同的符号。返回 x 的有符号小数部分。 整数部分作为浮点值存储在 intptr 中。

modf 具有使用Streaming SIMD Extensions 2(SSE2)的实现。 有关使用 SSE2 实现的信息和限制,请参阅 _set_SSE2_enable

C++ 允许重载,因此可以调用 modf 重载函数。 在 C 程序中,modf 始终采用两个双精度值并返回一个双精度值。

要求

例程

必需的标头

modf, modff

<math.h>

有关其他兼容性信息,请参见“简介”中的兼容性

C 运行时库的所有版本。

示例

// 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 );
}

Output

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

.NET Framework 等效项

请参见

参考

浮点支持

长双精度

frexp

ldexp