peterolson / BigRational.js

An arbitrary length rational number library for Javascript
The Unlicense
46 stars 15 forks source link

Lock up issues and no calculation OR RangeError: Maximum BigInt size exceeded #38

Open ganeshkbhat opened 1 year ago

ganeshkbhat commented 1 year ago

I am trying this var n = bigInt("3").pow("300530164787").minus("3").isDivisibleBy("300530164787"); and var n = bigInt("3").pow("3005301647874556767787878788787").minus("3").isDivisibleBy("3005301647874556767787878788787"); and bigRat(3).pow("300530164787").subtract(3).isDivisibleBy("300530164787") the node console is all locked up.

I am expecting the above to check if isDivisibleBy(value) returns an absolute integer and not a float. 300530164787%1 === 0 and 300530164787.234%1 === 0.234 or value%1 === 0

It also throws an error :

return new NativeBigInt(this.value * parseValue(v).value);
                                           ^

RangeError: Maximum BigInt size exceeded
    at NativeBigInt.multiply (C:\Users\GB\Documents\projects\requireurl\bigint.js:398:44)
    at NativeBigInt.pow (C:\Users\GB\Documents\projects\requireurl\bigint.js:670:23)
    at Object.<anonymous> (C:\Users\GB\Documents\projects\requireurl\bigint.js:1455:21)
    at Module._compile (node:internal/modules/cjs/loader:1149:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1203:10)
    at Module.load (node:internal/modules/cjs/loader:1027:32)
    at Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.10.0
var bigRat = require("big-rational");
let c = bigRat(3).pow("300530164787").subtract(3).divide("300530164787")
console.log(c);

// OR

var bigRat = require("big-rational");
let c = bigRat(3).pow("300530164787").subtract(3).isDivisibleBy("300530164787")
console.log(c);
peterolson commented 1 year ago

If you get the Maximum BigInt size exceeded error, that means you have exceeded the memory limitations. It seems that the V8 engine only allows up to one billion bits (see https://github.com/tc39/proposal-bigint/issues/174#issuecomment-437471065).

bigInt("3").pow("3005301647874556767787878788787") is an extremely huge number, so I would expect node.js to hang while it spends its time calculating. Even if there were no memory limitations, I'm not sure I would expect to get the result within the span of a human lifetime.