modf()、modff()、modfl() - 浮動小数点値の小数部と整数部の取り出し

標準

標準/拡張機能 C/C++ 依存項目

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification、バージョン 3
C++ TR1 C99

両方  

形式

#include <math.h>

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

機能説明

浮動小数点値の x を小数と整数の部分に分けます。 これらの整数部分は intptr が指すオブジェクトに double として保管されます。小数部分と整数部分の両方には、x と 同じ符号が指定されます。

制約事項

modff() 関数は、_FP_MODE_VARIABLE フィーチャー・テスト・マクロをサポートしません。

戻り値

x の符号付き小数部分を戻します。

CELEBM20
⁄* CELEBM20                                      

   This example breaks the floating-point number -14.876 into                   
   its fractional and integral components.                                      
                                                                                
 *⁄                                                                             
#include <math.h>                                                               
#include <stdio.h>                                                              
                                                                                
int main(void)                                                                  
{                                                                               
   double x, y, d;                                                              
                                                                                
   x = -14.876;                                                                 
   y = modf(x, &d);                                                             
                                                                                
   printf("x = %lf¥n", x);
   printf("Integral part = %lf¥n", d);
   printf("Fractional part = %lf¥n", y);
}                                                                               
出力:
x = -14.876000
Integral part = -14.000000
Fractional part = -0.876000

関連情報