fmod


function
<cmath>
     double fmod (      double numerator,      double denominator );
      float fmod (       float numerator,       float denominator );
long double fmod ( long double numerator, long double denominator );

Compute remainder of division

Returns the floating-point remainder of numerator/denominator.

The remainder of a division operation is the result of subtracting the integral quotient multiplied by the denominator from the numerator:

remainder = numerator - quotient * denominator

Parameters

numerator
Floating point value with the division numerator.
denominator
Floating point value with the division denominator.


Return Value

The remainder of dividing the arguments.

Portability

In C, only the double version of this function exists with this name.

Example

1
2
3
4
5
6
7
8
9
10
/* fmod example */
#include <stdio.h>
#include <math.h>

int main ()
{
  printf ("fmod of 5.3 / 2 is %lf\n", fmod (5.3,2) );
  printf ("fmod of 18.5 / 4.2 is %lf\n", fmod (18.5,4.2) );
  return 0;
}


Output:

fmod of 5.3 / 2 is 1.300000
fmod of 18.5 / 4.2 is 1.700000


See also