將浮點值分割成小數和整數部分。
語法
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
浮點值。
intptr
儲存之整數部分的指標。
傳回值
此函式會傳回 的 x帶正負號小數部分。 不會傳回錯誤。
備註
modf 函式會將浮點值 x 分解成小數和整數部分,每一部分的正負號都與 x 相同。
x 的帶正負號小數部分會傳回。 整數部分會儲存為 的 intptr浮點值。
modf 具有使用 Streaming SIMD Extensions 2 (SSE2) 的實作。 如需使用 SSE2 實作的資訊和限制,請參閱 _set_SSE2_enable 。
C++ 允許多載,因此您可以呼叫採用並傳回 modf 或 float 參數之 long double 的多載。 在 C 程式中,modf 會一律採用兩個雙精確度值並傳回一個雙精確度值。
根據預設,此函式的全域狀態會限定於應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。
需求
| 常式 | 必要的標頭 |
|---|---|
modf、 、 modffmodfl |
C: <math.h>C++: <cmath> 或 <math.h> |
如需相容性詳細資訊,請參閱相容性。
範例
// 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