ff4d84d1d26db6c828edfa5682d8a85b79d275b4728aa31c86d33b9b5a26a71e02499b5802723020f6241923fb296b34156398720819a0e818379bc9a98aa3 962 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var isNaN = require('../../helpers/isNaN');
  4. // https://262.ecma-international.org/11.0/#sec-numeric-types-number-remainder
  5. module.exports = function NumberRemainder(n, d) {
  6. if (typeof n !== 'number' || typeof d !== 'number') {
  7. throw new $TypeError('Assertion failed: `n` and `d` arguments must be Numbers');
  8. }
  9. // If either operand is NaN, the result is NaN.
  10. // If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
  11. if (isNaN(n) || isNaN(d) || !isFinite(n) || d === 0) {
  12. return NaN;
  13. }
  14. // If the dividend is finite and the divisor is an infinity, the result equals the dividend.
  15. // If the dividend is a zero and the divisor is nonzero and finite, the result is the same as the dividend.
  16. if (!isFinite(d) || (n === 0 && d !== 0)) {
  17. return n;
  18. }
  19. // In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved…
  20. return n % d;
  21. };