Export (0) Print
Expand All
div
eof
Expand Minimize
3 out of 7 rated this helpful - Rate this topic

fmod, fmodf 

Calculates the floating-point remainder.


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

Parameters

x, y

Floating-point values.

fmod returns the floating-point remainder of x / y. If the value of y is 0.0, fmod returns a quiet NaN. For information about representation of a quiet NaN by the printf family, see printf.

The fmod function calculates the floating-point remainder f of x / y such that x = i * y + f, where i is an integer, f has the same sign as x, and the absolute value of f is less than the absolute value of y.

C++ allows overloading, so you can call overloads of fmod. In a C program, fmod always takes two doubles and returns a double.

Function Required header Compatibility

fmod, fmodf

<math.h>

ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

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

Output

The remainder of -10.00 / 3.00 is -1.000000
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.