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