Function mathModulo

  • This implementation follows Knuth's definition, mod(a, n) = a - n * floor(a / n), which reflects the mathematical definition of modular arithmetic better than JavasScript's % operator. (The primary difference is in handling negative numbers.) For an implementation of the JavaScript % operator, see modulo.

    Example

    import * as N from "flurp/number";

    const hueIn0to360 = N.mathModulo(360);
    hueIn0to360(390); // 30
    hueIn0to360(-60); // 300

    Parameters

    • y: number

    Returns ((x: number) => number)

      • (x: number): number
      • Parameters

        • x: number

        Returns number