petite-utils
Version:
A collection of small util function in JavaScript.
31 lines (30 loc) • 954 B
TypeScript
/**
* m mod n,
* it is different from % operator in javascript
* % operator is remainder operator, m % n is same to m - n * Math.trunc(m / n).
* Modulo operator is m mod n is same to m - n * Math.floor(m / n)
* {@link https://www.designcise.com/web/tutorial/what-is-the-difference-between-the-javascript-remainder-operator-and-the-modulo-operator}
* @example
* modulo(7, 3) // 1
* modulo(-7, -3) // -1
* modulo(7, -3) // -2
* modulo(-7, 3) // 2
* @param m
* @param n
* @returns
*/
declare function modulo(m: number, n: number): number;
/**
* m remainder n 取余数
* @example
* remainder(7, 3) // 1
* remainder(-7, 3) // -1
* remainder(7, -3) // 1
* remainder(-7, -3) // -1
* @param dividend
* @param divisor
* @returns remainder
* {@link https://stackoverflow.com/questions/38702724/math-floor-vs-math-trunc-javascript}
*/
declare function remainder(dividend: number, divisor: number): number;
export { modulo, remainder };