drem
Compute the remainder of floating-point x/y.
That is, x = n * y + d, where n is an integer and |d| < y/2. When |d| = |y|/2, ensure that n is an even number.
Interface Definition
C interface:
float dremf(float x, float y);
double drem(double x, 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
- Normal range: The remainder of x/y is returned.
- Special range:
- If the input |x| or |y| is 0 or NaN, the output is NaN.
- If the input |x| is 0 and |y| is not 0 or NaN, the output is ±0.
Dependency
C: "km.h"
Example
C interface:
// typical usage
double x1 = 3.0, x2 = 3.5;
double y1 = 4.0, y2 = 4.5;
// special handling
double e = INFINITY, f = -INFINITY, g = NAN;
// print result
printf("/*\n");
printf(" * drem(3.0, 4.0) = %.15f\n", drem(x1, y1));
printf(" * drem(3.5, 4.5) = %.15f\n", drem(x2, x2));
printf(" * drem(4.5, 4.5) = %.15f\n", drem(y2, y2));
printf(" * drem(INFINITY, 0) = %.15f\n", drem(e, 0.0f));
printf(" * drem(-INFINITY, 3.0) = %.15f\n", drem(f, x1));
printf(" * drem(NAN, 3.0) = %.15f\n", drem(g, x1));
printf(" * drem(NAN, INFINITY) = %.15f\n", drem(g, e));
printf(" **/\n");
/*
* drem(3.0, 4.0) = -1.000000000000000
* drem(3.5, 4.5) = 0.000000000000000
* drem(4.5, 4.5) = 0.000000000000000
* drem(INFINITY, 0) = nan
* drem(-INFINITY, 3.0) = nan
* drem(NAN, 3.0) = nan
* drem(NAN, INFINITY) = nan
**/
Parent topic: Remainder Functions