0

I am not sure how dumb this question is, but I have an algorithm that outputs huge numbers (more than 1e300). I have tried the arbitrary precision library mpmat bu now I want to stick with numpy.

as a simple example, how can I store 1e400 without getting inf ?

a = 1e400

I know that I should have more bits storage, but I don't know if there is a way to have less significant numbers while keeping the exponent.

cel
  • 30,017
  • 18
  • 97
  • 117
Santi Peñate-Vera
  • 1,053
  • 4
  • 33
  • 68
  • 5
    Can you use logarithmic representations? – dawg Jan 14 '16 at 20:23
  • 1
    [here is a related post](http://stackoverflow.com/questions/21945923/how-to-compute-huge-numbers-with-python). You could use "decimal" numbers which are basically strings with arithmetic operations... Since the numbers are strings you can calculate in principle whatever you want. – Nicolas Heimann Jan 14 '16 at 20:23
  • @keksnicoh, this will eat all of the performance and is rarely a good idea. – cel Jan 14 '16 at 20:24
  • Yep thats true. But as a first approach could be enough if you only need to calculate a small set of operations. – Nicolas Heimann Jan 14 '16 at 20:25
  • 2
    what is the range in values? you could scale from the minimum or about the mean as an alternative. –  Jan 14 '16 at 20:26
  • Decimal could do the trick, but since I have convolutions involved the performance would be awful. – Santi Peñate-Vera Jan 14 '16 at 20:34
  • 2
    More information is needed. The suggestions to work with logarithms, or use a better scaling, are good, but without knowing more about *why* you have such large numbers, we can't really answer the question. – Warren Weckesser Jan 14 '16 at 21:37
  • I am curious : which real problem need such a dynamic ? – B. M. Jan 15 '16 at 18:09
  • It is called holomorphic embedding power flow and it involves the calculation of coefficients that grow exponentially, funny enough each coefficient brings extra precision to a final solution, and I want to check that if it is the magnitude what brigs extra precision or if I need all the numbers – Santi Peñate-Vera Jan 16 '16 at 20:39

0 Answers0