Anteckning
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Calculates the floating-point remainder.
Syntax
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
);
long double fmodl(
long double x,
long double y
);
#define fmod(X, Y) // Requires C11 or later
Parameters
x, y
Floating-point values.
Return value
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.
Remarks
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 that take and return float and long double values. In a C program, unless you're using the <tgmath.h> macro to call this function, fmod always takes two double arguments and returns a double.
If you use the fmod macro from <tgmath.h>, the type of the argument determines which version of the function is selected. See Type-generic math for details.
By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.
Requirements
| Function | Required header |
|---|---|
fmod, fmodf, fmodl |
<math.h> |
fmod macro |
<tgmath.h> |
For more compatibility information, see Compatibility.
Example
// 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 );
}
The remainder of -10.00 / 3.00 is -1.000000
See also
Math and floating-point support
ceil, ceilf, ceill
fabs, fabsf, fabsl
floor, floorf, floorl
_CIfmod