fmod, fmodf, fmodl

浮動小数点の剰余を計算します。

構文

double fmod(
   double x,
   double y
);
float fmod(
   float x,
   float y
);  // C++ only
long double fmod(
   long double x,
   long double y
);  // C++ only
float fmodf(
   float x,
   float y
);
long double fmodl(
   long double x,
   long double y
);

#define fmod(X, Y) // Requires C11 or higher

パラメーター

x, y
浮動小数点値。

戻り値

fmod は、x / y の浮動小数点の剰余を返します。 y の値が 0.0 の場合、fmod では簡易な NaN を返します。 printf 系による簡易な NaN の表現については、printf に関するページを参照してください。

解説

fmod 関数は、x = i * y + f となる x / y の剰余 f を浮動小数点型で計算します。i は整数であり、f の符号は x と同じであり、f の絶対値は y の絶対値未満です。

C++ ではオーバーロードが可能であるため、fmod および float の値を受け取って返す long double のオーバーロードを呼び出すことができます。 C プログラムでは、<tgmath.h> マクロを使用してこの関数を呼び出す場合を除き、fmod では常に 2 つの double の引数を受け取って double を返します。

マクロを<tgmath.h>使用するfmod場合は、引数の型によって、どのバージョンの関数が選択されているかが決まります。 詳細については、「ジェネリック型数値演算」を参照してください。

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

必要条件

機能 必須ヘッダー
fmod, fmodf, fmodl <math.h>
fmod マクロ <tgmath.h>

互換性の詳細については、「 Compatibility」を参照してください。

// crt_fmod.c
// This program displays a floating-point remainder.

#include <math.h>
#include <stdio.h>

int main( void )
{
   double w = -10.0, x = 3.0, z;

   z = fmod( w, x );
   printf( "The remainder of %.2f / %.2f is %f\n", w, x, z );
}
The remainder of -10.00 / 3.00 is -1.000000

関連項目

数学と浮動小数点のサポート
ceil, ceilf, ceill
fabs, fabsf, fabsl
floor, floorf, floorl
_CIfmod