remainderremainderfremainderl

2 つの浮動小数点値の商の剰余を最も近い整数値に丸めて計算します。

構文

double remainder( double x, double y );
float remainderf( float x, float y );
long double remainderl( long double x, long double y );
#define remainder(X, Y) // Requires C11 or higher

float remainder( float x, float y ); /* C++ only */
long double remainder( long double x, long double y ); /* C++ only */

パラメーター

x
分子。

y
分母。

戻り値

x / y の浮動小数点型の剰余。 y の値が 0.0 の場合、remainder は簡易な NaN を返します。 printf ファミリによる静かな NaN の表現については、「printf_printf_lwprintf_wprintf_l」を参照してください。

解説

remainder関数は、x / yの浮動小数点×余rを計算します。x = n * y + rでは、nx / yに最も近い値で、nは常に|n - x / y| = 1/2場合でも整数です。 r = 0すると、rxと同じ符号を持つ。

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

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

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

要件

機能 必須ヘッダー (C) 必須ヘッダー (C++)
remainderremainderfremainderl <math.h> <cmath> または <math.h>
remainder マクロ <tgmath.h>

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

// crt_remainder.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 = remainder(w, x);
   printf("The remainder of %.2f / %.2f is %f\n", w, x, z);
}
The remainder of -10.00 / 3.00 is -1.000000

関連項目

数値演算と浮動小数点のサポート
ldiv, lldiv
imaxdiv
fmod, fmodf
remquoremquofremquol