source: node_modules/ramda/es/mathMod.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import _curry2 from "./internal/_curry2.js";
2import _isInteger from "./internal/_isInteger.js";
3/**
4 * `mathMod` behaves like the modulo operator should mathematically, unlike the
5 * `%` operator (and by extension, [`R.modulo`](#modulo)). So while
6 * `-17 % 5` is `-2`, `mathMod(-17, 5)` is `3`. `mathMod` requires Integer
7 * arguments, and returns NaN when the modulus is zero or negative.
8 *
9 * @func
10 * @memberOf R
11 * @since v0.3.0
12 * @category Math
13 * @sig Number -> Number -> Number
14 * @param {Number} m The dividend.
15 * @param {Number} p the modulus.
16 * @return {Number} The result of `b mod a`.
17 * @see R.modulo
18 * @example
19 *
20 * R.mathMod(-17, 5); //=> 3
21 * R.mathMod(17, 5); //=> 2
22 * R.mathMod(17, -5); //=> NaN
23 * R.mathMod(17, 0); //=> NaN
24 * R.mathMod(17.2, 5); //=> NaN
25 * R.mathMod(17, 5.3); //=> NaN
26 *
27 * const clock = R.mathMod(R.__, 12);
28 * clock(15); //=> 3
29 * clock(24); //=> 0
30 *
31 * const seventeenMod = R.mathMod(17);
32 * seventeenMod(3); //=> 2
33 * seventeenMod(4); //=> 1
34 * seventeenMod(10); //=> 7
35 */
36
37var mathMod =
38/*#__PURE__*/
39_curry2(function mathMod(m, p) {
40 if (!_isInteger(m)) {
41 return NaN;
42 }
43
44 if (!_isInteger(p) || p < 1) {
45 return NaN;
46 }
47
48 return (m % p + p) % p;
49});
50
51export default mathMod;
Note: See TracBrowser for help on using the repository browser.