source: imaps-frontend/node_modules/es-abstract/2024/Number/remainder.js@ d565449

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: 1.2 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var isNaN = require('../../helpers/isNaN');
6var isFinite = require('../../helpers/isFinite');
7
8var truncate = require('../truncate');
9
10// https://262.ecma-international.org/14.0/#sec-numeric-types-number-remainder
11
12module.exports = function NumberRemainder(n, d) {
13 if (typeof n !== 'number' || typeof d !== 'number') {
14 throw new $TypeError('Assertion failed: `n` and `d` arguments must be Numbers');
15 }
16
17 // If either operand is NaN, the result is NaN.
18 // If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
19 if (isNaN(n) || isNaN(d) || !isFinite(n) || d === 0) {
20 return NaN;
21 }
22
23 // If the dividend is finite and the divisor is an infinity, the result equals the dividend.
24 // If the dividend is a zero and the divisor is nonzero and finite, the result is the same as the dividend.
25 if (!isFinite(d) || n === 0) {
26 return n;
27 }
28
29 if (!isFinite(n) || !isFinite(d) || n === 0 || d === 0) {
30 throw new $TypeError('Assertion failed: `n` and `d` arguments must be finite and nonzero');
31 }
32 var quotient = n / d;
33 var q = truncate(quotient);
34 var r = n - (d * q);
35 if (r === 0 && n < 0) {
36 return -0;
37 }
38 return r;
39};
Note: See TracBrowser for help on using the repository browser.