modf, modff, modfl

浮動小数点値を小数部と整数部に分割します。

構文

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 には、ストリーミング SIMD 拡張機能 (SSE2) を使用して実装されています。 SSE2 実装の使い方の詳細および制約については、「_set_SSE2_enable」を参照してください。

C++ ではオーバーロードができるため、float または long double のパラメーターを受け取って返す modf のオーバーロードを呼び出すことができます。 C プログラムでは、modf は常に 2 個の double 値を受け取って、double 値を返します。

既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT のグローバル状態」を参照してください

必要条件

ルーチンによって返される値 必須ヘッダー
modf, modff, modfl C: <math.h>

C++: , <cmath> または <math.h>

互換性の詳細については、「 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

関連項目

数学と浮動小数点のサポート
frexp
ldexp