remainder, remainderf, remainderl

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_l, wprintf_wprintf_l参照してくださいprintf

解説

関数はremainder、値の中でx / yn最も近い整数であり、常|n - x / y| = 1/2に偶数になるように、浮動小数点の再メインをx = n * y + rrx / yn計算します。 と r = 0き、 r と同じ符号 xを持つ。

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

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

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

必要条件

機能 必須ヘッダー (C) 必須ヘッダー (C++)
remainder, remainderf, remainderl <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
remquo, remquof, remquol