I am looking for a Java library that can handle truly huge numbers or suggestions as to how to implement this myself. We are talking way beyond BigInteger
. How about 2^39614081257132168796771974655+1 for example.
Clearly I could, theoretically, make use of a TreeSet<BigInteger>
, one entry per bit and do all the math old-school but I am looking for something that can actually do some real maths with these numbers using built-in math hardware. I don't expect anything truly fast but I would very much like to get close.
It is likely that the number of set bits may be quite small - I am representing G2 polynomials.
Does anyone know of anything out there?
I suspect a feature of the package must be a setBit(BigInteger i)
.
Added
Thanks for the suggestion of Apfloat. Sadly the following is not possible. It complains that the second parameter must be a long
.
Apint two = new Apint(2);
Apint big = new Apint("39614081257132168796771974655");
ApintMath.pow(two, big);
Please note that I am also open to suggestions as to how to do this myself.
Added - to attempt a reopen.
Please see user2246674's post reminding us how staggeringly enormous these numbers are - I can assure you we are not talking about some ordinary math library here, we are talking some serious Math.pow(age-of-the-universe,atoms-in_the_galaxy)
kind of numbers - we are certainly not looking for mere opinionated answers.
This isn't an answer; it is here because I think it's important to realize how insanely big such a number is and why a standard arbitrary precision math library will not work - ever.
The library must have support to directly deal with higher-order equations (such as that which powers Wolfram|Alpha). I believe this is a good question to have on SO specifically because numbers of this magnitude must be treated special.
A standard bit encoding won't work here - if this were possible then BigInteger would also likely suffice (as would Apfloat which was mentioned). The fundamental problem is that 2^39614081257132168796771974655 is huge. Like, really, really big. It only makes sense to deal with numbers of this size using equations!
Let's reason how much a standard one's or two's complement encoding takes by looking at the storage required for several common maximum integer values:
Thus, 2^39614081257132168796771974655 requires 39614081257132168796771974655/8 (or ~5x10^27) bytes of memory if using a similar encoding.
A terabyte of memory is only 1x10^12 bytes: it requires more than a QUADRILLION TERABYTES to use a standard encoding on a number of this magnitude.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With