[Previous] [Contents] [Next]

fmod(), fmodf()

Compute a floating-point modulus

Synopsis:

#include <math.h>

double fmod( double x, 
             double y );


float fmodf( float x, 
             float y );

Library:

libm

Description:

The fmod() and fmodf() functions compute the floating-point remainder of x / y, even if the quotient x / y isn't representable.

Returns:

x - (i * y)

For an integer i such that:

If y is: fmod() returns:
0 0
=/=0 The same sign as x, and a magnitude less than the magnitude of y.

Examples:

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

int main( void )
{
    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 ) );

    return EXIT_SUCCESS;
}

produces the output:

0.500000
-0.500000
0.500000
-0.500000

Classification:

ANSI

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

See also:

ceil(), div(), fabs(), floor()


[Previous] [Contents] [Next]