次の方法で共有

Facebook x.com LinkedIn 電子メール

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 関数は、浮動小数点値 xx と同じ符号の小数部分と整数部分に分割します。x の符号付きの小数部分が返されます。 整数部分は、intptr の指す領域に、浮動小数点値として格納されます。

modf には、SSE2 (Streaming SIMD Extensions 2) を使用する実装があります。 SSE2 実装の使用に関する情報と制限については、「_set_SSE2_enable」を参照してください。

C++ ではオーバーロードが可能であるため、modf のオーバーロードを呼び出すことができます。 C プログラムでは、modf は常に 2 つの倍精度浮動小数点数型の値を受け取り、1 つの倍精度浮動小数点数型の値を返します。

必要条件

ルーチン

必須ヘッダー

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

同等の .NET Framework 関数

参照

参照

浮動小数点サポート

Long Double 型

frexp

ldexp


  • Last updated on 2011年08月09日