Share via


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 。 如需家族之無訊息 NaN 表示的詳細資訊,請參閱 printfprintf

備註

如果 x = i * y + f,則 fmod 函式會計算 x / y 的浮點餘數 f,其中 i 是整數、f 的正負號與 x 相同,而且 f 的絕對值小於 y 的絕對值。

C++ 允許多載,因此您可以呼叫採用並傳回 floatlong double 值之 fmod 的多載。 在 C 程式中,除非您使用 <tgmath.h> 宏來呼叫此函式, fmod 否則一律會採用兩 doubledouble 引數並傳回 。

如果您使用 中的 fmod<tgmath.h> 宏,引數的類型會決定選取哪一個函式版本。 如需詳細資訊,請參閱 類型泛型數學

根據預設,此函式的全域狀態會限定于應用程式。 若要變更此行為,請參閱 CRT 中的全域狀態。

需求

函式 必要的標頭
fmod, fmodf, fmodl <math.h>
fmod 宏觀 <tgmath.h>

如需相容性詳細資訊,請參閱相容性

範例

// 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