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 に ストリーミング SIMD 拡張機能 2 (SSE2) を使用して実装できます。 SSE2 実装を情報と使用条件の _set_SSE2_enable を参照してください。
C++ ではオーバーロードが可能であるため、modf のオーバーロードを呼び出すことができます。 C プログラムでは、modf .は 2 個の double 値を常に取得し、その値を返します。
必要条件
ルーチン |
必須ヘッダー |
---|---|
modf, modff |
<math.h> |
互換性の詳細については、「C ランタイム ライブラリ」の「互換性」を参照してください。
ライブラリ
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 );
}
出力
For -14.876543, the fraction is -0.876543 and the integer is -14