@tgsnake/skema
    Preparing search index...

    Function mod

    • Computes the true mathematical modulo of two JS standard numbers, ensuring a non-negative result.

      Parameters

      • n: number

        The dividend.

      • m: number

        The divisor (must be a positive, non-zero number).

      Returns number

      The positive remainder representing n mod m.

      In standard JavaScript, the % operator computes the remainder, which can result in a negative number if the dividend n is negative. This helper function corrects that behavior to return a mathematically sound positive modulo in the range [0, m).

      mod(5, 3);   // returns 2
      mod(-1, 3); // returns 2 (whereas -1 % 3 returns -1)