remainder

Calculate the remainder x REM y, following IEC 60559.

REM is the value of x - y * n, where n is the integer nearest the exact value of x / y. If |n - x / y| == 0.5, n is even. If the result is zero, it has the same sign as x. Otherwise, the sign of the result is the sign of x / y. Precision mode has no effect on the remainder functions.

remquo returns n in the parameter n.

Special Values
xyremainder(x, y)ninvalid?
±0.0not 0.0±0.00.0no
$(PLUSMNINF)anything-NaN?yes
anything±0.0±NaN?yes
!= $(PLUSMNINF)$(PLUSMNINF)x?no
@trusted nothrow @nogc
real
remainder
(
real x
,
real y
)

Examples

import std.math.operations : feqrel;
import std.math.traits : isNaN;

assert(remainder(5.1, 3.0).feqrel(-0.9) > 16);
assert(remainder(-5.1, 3.0).feqrel(0.9) > 16);
assert(remainder(0.0, 3.0) == 0.0);

assert(isNaN(remainder(1.0, 0.0)));
assert(isNaN(remainder(-1.0, 0.0)));
import std.math.operations : feqrel;

int n;

assert(remquo(5.1, 3.0, n).feqrel(-0.9) > 16 && n == 2);
assert(remquo(-5.1, 3.0, n).feqrel(0.9) > 16 && n == -2);
assert(remquo(0.0, 3.0, n) == 0.0 && n == 0);

Meta