Mod v0.1.0

Source
Returns the floating-point remainder of x / y.

Package: Math

Signature

func Mod(x: float64, y: float64) -> float64;
func Mod(x: float32, y: float32) -> float32;

Parameters

NameTypeDescription
xfloat64 / float32The dividend.
yfloat64 / float32The divisor.

Returns

The exact remainder x - n * y, for the integer n that truncates x / y, matching C's fmod. The result carries the sign of x; it is x unchanged when |x| < |y|, and a zero signed like x when |x| == |y|.

The result is a NaN when y is zero, when y is a NaN, or when x is infinite or a NaN.

Example

import Math::Mod;

func Main() -> int {
    let a = Mod(5.5, 2.0);  // 1.5
    let b = Mod(-5.5, 2.0); // -1.5
    return 0;
}

See also

  • Math — the package overview
  • Trunc — the truncation Mod reduces against