DKL9 GitList
Repositories
DKL9 home
rtensor
Code
Commits
Branches
Tags
Search
Tree:
117473e
Branches
Tags
master
rtensor
types
bigint.js
Refactor towards a working QuickJS version
dkl9
commited
117473e
at 2023-196 12:46:40
bigint.js
Blame
History
Raw
"use strict"; import {BasicNumber} from "./basic.js"; BasicNumber.keys.forEach(k => (BigInt.prototype[k] = BasicNumber.prototype[k])); BigInt.ify = function(x) { if (typeof x == "object" && x.constructor == Complex) { return x.im ? null : BigInt(Math.floor(x.re)); } else if (typeof x == "number") { return BigInt(x); } else { return x; } }; BigInt.prototype.invalid = () => false; BigInt.zero = () => 0n; BigInt.one = () => 1n; BigInt.prototype.add = function(n) { return this + n; }; BigInt.prototype.neg = function() { return -this; }; BigInt.prototype.mul = function(n) { return this * n; }; BigInt.prototype.div = function(n) { return this / n; }; BigInt.prototype.exp = function() { return 2n ** this; }; BigInt.prototype.pow = function(n) { return this ** n; }; BigInt.prototype.eq = function(n) { return this == n; }; BigInt.prototype.lt = function(n) { return this < n; }; BigInt.prototype.mag = function() { return Math.abs((new Number(this)).valueOf()); }; BigInt.prototype.floor = function() { return this; };