fmod
Compute the modulus of x with respect to y, that is x modulo y. x and y are of the floating-point type.
Interface Definition
C interface:
float fmodf(float x, float y);
double fmod(double x, double y);
long double fmodl(long double x, long double y);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of the input data. |
Input |
y |
|
Floating-point value of the input data. |
Input |
Return Value
- The result of x modulo y is returned.
- If x is any value and y is ±0 or NaN, the return value is NaN.
- If x is ±0 and y is not ±0 or NaN, the return value is ±0.
- If x is ±∞ or NaN and y is any value, the return value is NaN.
Dependencies
C: "km.h"
Examples
C interface:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | // typical usage float x1 = -1.0, x2 = 2.0, x3 = 3.0, x4 = 4.0; float y1 = 4.0, y2 = -4.0, y3 = -3.0, y4 = 3.0; // special handling float a = 0.0, b = INFINITY, c = -INFINITY, d = NAN; // print result printf("fmodf(-1.0, 4.0) = %.6f\n", fmodf(x1, y1)); printf("fmodf(2.0, -4.0) = %.6f\n", fmodf(x2, y2)); printf("fmodf(3.0, -3.0) = %.6f\n", fmodf(x3, y3)); printf("fmodf(4.0, 3.0) = %.6f\n", fmodf(x4, y4)); printf("fmodf(1.0, 0.0) = %+.6f\n", fmodf(x1, a)); printf("fmodf(INFINITY, 1.0) = %+.6f\n", fmodf(b, x1)); printf("fmodf(-INFINITY, -1.0) = %+.6f\n", fmodf(c, -x1)); printf("fmodf(1.0, -INFINITY) = %+.6f\n", fmodf(x1, c)); printf("fmodf(1.0, NAN) = %+.6f\n", fmodf(x1, d)); printf("fmodf(NAN, -1.0) = %+.6f\n", fmodf(d, -x1)); /* * fmodf(-1.0, 4.0) = -1.000000 * fmodf(2.0, -4.0) = 2.000000 * fmodf(3.0, -3.0) = 0.000000 * fmodf(4.0, 3.0) = 1.000000 * fmodf(1.0, 0.0) = -nan * fmodf(INFINITY, 1.0) = -nan * fmodf(-INFINITY, -1.0) = -nan * fmodf(1.0, -INFINITY) = +1.000000 * fmodf(1.0, NAN) = +nan * fmodf(NAN, -1.0) = +nan * */ |
Parent topic: Remainder Functions