共用方式為


fmod fmodf

計算浮點數餘數。

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 
);

參數

  • x, y
    浮點數值。

傳回值

fmod傳回的浮點數餘數x / y。 如果值為y為 0.0, fmod傳回安靜 NaN。 有關如何藉由為無訊息 NaN 表示printf家族,請參閱 printf

備註

fmod函式會計算浮點數餘數f的x / y , x = i*y + f,其中i是一個整數, f有相同的簽章,為x,和數值的絕對值f數值的絕對值小於y。  

C + + 允許多載化,因此您可以呼叫多載的fmod。 在某 c 程式, fmod永遠會接受兩個雙精度浮點數,並傳回 double。

需求

Function

所需的標頭

fmod, fmodf

<math.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 );
}
  

.NET Framework 對等用法

System::Math::IEEERemainder

請參閱

參考

浮點支援

ceil ceilf

fabs fabsf

floor, floorf

_CIfmod