Function positiveModulo

  • This is similar to numerator % denominator, i.e. modulo division. The difference is that the result will never be negative. If the numerator is negative % will return a negative number.

    If the 0 point is chosen arbitrarily then you should use positiveModulo() rather than %. For example, C's time_t and JavaScript's Date.prototype.valueOf() say that 0 means midnight January 1, 1970. Negative numbers refer to times before midnight January 1, 1970, and positive numbers refer to times after midnight January 1, 1970. But midnight January 1, 1970 was chosen arbitrarily, and you probably don't want to treat times before that differently than times after that. And how many people would even think to test a negative date?

    positiveModulo(n, d) will give the same result as positiveModulo(n + d, d) for all vales of n and d. (You might get 0 sometimes and -0 other times, but those are both == so I'm not worried about that.)

    Parameters

    • numerator: number
    • denominator: number

    Returns number