Is there a library for huge integers

I am looking for a Java library that can handle really huge numbers or suggestions on how to implement this yourself. We talk about this above BigInteger . How about 2 ^ 39614081257132168796771974655 + 1 .

Clearly, theoretically, I could use TreeSet<BigInteger> , one write per bit and do the whole math school, but I'm looking for something that can actually do some real math with these numbers using the built-in math hardware. I do not expect anything really fast, but I would really like to get closer.

Probably the number of set bits can be quite small - I represent the polynomials G2.

Does anyone know anything there?

I suspect the package function should be setBit(BigInteger i) .

Added

Thanks for the suggestion of Apfloat . Unfortunately, impossible. He complains that the second parameter should be long .

  Apint two = new Apint(2); Apint big = new Apint("39614081257132168796771974655"); ApintMath.pow(two, big); 

Please note that I am also open to suggestions on how to do this myself.

Added - to reopen.

Please see user2246674 post , reminding us how tremendously huge these numbers are. I can assure you, we are not talking about some ordinary mathematical library, we are talking about serious Math.pow(age-of-the-universe,atoms-in_the_galaxy) kind of numbers - we , of course , are not looking for simple stubborn answers.

+4
source share
2 answers

This is not an answer; this is because I think it is important to understand how insanely large such a number is and why the standard math library will not work with arbitrary precision.

The library should have support for dealing directly with higher order equations (for example, those with Wolfram | Alpha ). I think this is a good question related to SO precisely because numbers of this magnitude should be considered special.


Standard bit coding will not work here - if it were possible, then BigInteger would probably also be sufficient (as Apfloat would mention). The main problem is that 2 ^ 39614081257132168796771974655 is huge. It seems, really, really big. It makes sense to deal with numbers of this size using equations!

Explain how much the standard one or two add-on encodings are required if you look at the storage required for several common maximum integer values:

  • 2 ^ 8 takes 8 bits; or 1 byte (8/8)
  • 2 ^ 32 takes 32 bits; or 4 bytes (32/8)
  • 2 ^ 64 accepts 64 bits; or 8 bytes (64/8)

Thus, 2 ^ 39614081257132168796771974655 requires 39614081257132168796771974655/8 (or ~ 5x10 ^ 27) bytes of memory when using the same encoding.

A terabyte of memory is only 1x10 ^ 12 bytes: to use standard encoding at the level of this value

more than QUADRILLION TERABYTES required.
+8
source

You can do the math on this, but only based on symbolic calculations, i.e. you cannot reduce this to a real number, you can process this expression only.

Can you give an example of the operations you want to perform?

+2
source

Source: https://habr.com/ru/post/1486724/


All Articles