remainder
, remainderf
, remainderl
計算兩個浮點值商數的餘數,四捨五入為最接近的整數值。
語法
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。 如需家族中無訊息 NaN printf
標記法的詳細資訊,請參閱 printf
、 、 _wprintf_l
_printf_l
wprintf
、 。
備註
函 remainder
式會計算 的浮點餘數 r
x / y
, x = n * y + r
使 ,其中 n
是值最接近的 x / y
n
整數,即使每當 |n - x / y| = 1/2
。 當 時 r = 0
, r
具有與 x
相同的符號。
因為 C++ 允許多載,所以您可以呼叫採用並傳回 remainder
或 float
值的 long double
的多載。 在 C 程式中,除非您使用 < tgmath.h > 宏來呼叫此函式, remainder
否則一律會採用兩 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
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應