main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
962 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var $TypeError = require('es-errors/type');
|
---|
4 |
|
---|
5 | var isNaN = require('../../helpers/isNaN');
|
---|
6 |
|
---|
7 | // https://262.ecma-international.org/11.0/#sec-numeric-types-number-remainder
|
---|
8 |
|
---|
9 | module.exports = function NumberRemainder(n, d) {
|
---|
10 | if (typeof n !== 'number' || typeof d !== 'number') {
|
---|
11 | throw new $TypeError('Assertion failed: `n` and `d` arguments must be Numbers');
|
---|
12 | }
|
---|
13 |
|
---|
14 | // If either operand is NaN, the result is NaN.
|
---|
15 | // If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
|
---|
16 | if (isNaN(n) || isNaN(d) || !isFinite(n) || d === 0) {
|
---|
17 | return NaN;
|
---|
18 | }
|
---|
19 |
|
---|
20 | // If the dividend is finite and the divisor is an infinity, the result equals the dividend.
|
---|
21 | // If the dividend is a zero and the divisor is nonzero and finite, the result is the same as the dividend.
|
---|
22 | if (!isFinite(d) || (n === 0 && d !== 0)) {
|
---|
23 | return n;
|
---|
24 | }
|
---|
25 |
|
---|
26 | // In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved…
|
---|
27 | return n % d;
|
---|
28 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.