Going past the float size limits?

Matt McCredie mccredie at gmail.com
Sat Oct 27 01:00:36 CEST 2007


> It would be great if I could make a number that can go beyond current
> size limitations. Is there any sort of external library that can have
> infinitely huge numbers? Way way way way beyond say 5x10^350 or
> whatever it is?
>
> I'm hitting that "inf" boundary rather fast and I can't seem to work
> around it.


You have a couple of options.
1. Use long if that is appropriate for your data, they can be as large
as you want (eventually you will reach memory constraints, but that
isn't likely)
2. There is a decimal type, which is based on long (I think) and can
have a decimal portion.

to use longs:
x = 5 * 10**350

to use decimal:
import decimal
x = decimal.Decimal("5e350")

You will probably want to read up on  the decimal module.

Matt



More information about the Python-list mailing list