Going past the float size limits?

mensanator at aol.com mensanator at aol.com
Fri Oct 26 20:21:04 EDT 2007


On Oct 26, 6:29 pm, jimmy.musselwh... at gmail.com wrote:
> On Oct 26, 6:56 pm, "Chris Mellon" <arka... at gmail.com> wrote:
>
> > On 10/26/07, jimmy.musselwh... at gmail.com <jimmy.musselwh... at gmail.com> wrote:
>
> > > Hello all
> > > 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.
>
> > What in the world are you trying to count?
>
> The calculation looks like this
>
> A = 0.35
> T = 0.30
> C = 0.25
> G = 0.10
>
> and then I basically continually multiply those numbers together. I
> need to do it like 200,000+ times but that's nuts. I can't even do it
> 1000 times or the number rounds off to 0.0. I tried taking the inverse
> of these numbers as I go but then it just shoots up to "inf".

As mentioned elsewhere, gmpy is a possible solution. You can do
the calculations with unlimited precision rationals without
introducing any rounding errors and then convert the final
answer to unlimited precision floating point without ever
hitting 0 or inf:

>>> import gmpy
>>> A = gmpy.mpq(35,100)
>>> b = A**200000
>>> c = gmpy.mpf(b)
>>> gmpy.fdigits(c)
'4.06321735803245162316e-91187'




More information about the Python-list mailing list