divide.js 597 B

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