[Previous]
[Contents]
[Next]

fmod()

compute a floating-point modulus

Synopsis:

#include <math.h>
double fmod( double x, double y );

Description:

The fmod() function computes the floating-point remainder of x/y, even if the quotient x/y isn't representable.

Returns:

The value x - (i * y), for some integer i such that, if y is nonzero, the result has the same sign as x, and magnitude less than the magnitude of y. If the value of y is zero, the value returned is zero.

Examples:

#include <stdio.h>
#include <math.h>

void main()
  {
    printf( "%f\n", fmod(  4.5,  2.0 ) );
    printf( "%f\n", fmod( -4.5,  2.0 ) );
    printf( "%f\n", fmod(  4.5, -2.0 ) );
    printf( "%f\n", fmod( -4.5, -2.0 ) );
  }

produces the output

0.500000
-0.500000
0.500000
-0.500000

Classification:

ANSI

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

ceil(), fabs(), floor()


[Previous]
[Contents]
[Next]