Math module

fmod_cycling

procedure · 2 overloadsSource

x wrapped into [0, divisor) as x - floor(x / divisor) * divisor: the result has the sign of divisor, so a negative x cycles around instead of going negative (unlike the C fmod). A zero divisor prints a message to standard error and returns infinity.

ExampleOpen in playground ↗
assert(fmod_cycling(7.0, 3.0) == 1);
assert(fmod_cycling(-1.0, 3.0) == 2);
assert(fmod_cycling(5.5, 2.0) == 1.5);
fmod_cycling :: (x: float64, y: float64) -> float64

Remainder of x / y that takes the sign of y, so the result cycles through 0..y. A zero divisor prints a message and returns infinity.

Parameters

x: float64
the dividend.
y: float64
the divisor.

Returns

float64
fmod_cycling :: (x: float, divisor: float) -> float

Remainder of x / divisor that takes the sign of divisor, so the result cycles through 0..divisor.

Parameters

x: float
the dividend.
divisor: float
the divisor. Zero prints a message and returns infinity.

Returns

float

See also