divide.js 631 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $BigInt = GetIntrinsic('%BigInt%', true);
  4. var $RangeError = GetIntrinsic('%RangeError%');
  5. var $TypeError = GetIntrinsic('%TypeError%');
  6. var Type = require('../Type');
  7. // https://262.ecma-international.org/11.0/#sec-numeric-types-bigint-divide
  8. module.exports = function BigIntDivide(x, y) {
  9. if (Type(x) !== 'BigInt' || Type(y) !== 'BigInt') {
  10. throw new $TypeError('Assertion failed: `x` and `y` arguments must be BigInts');
  11. }
  12. if (y === $BigInt(0)) {
  13. throw new $RangeError('Division by zero');
  14. }
  15. // shortcut for the actual spec mechanics
  16. return x / y;
  17. };