curious problem with large numbers

David M. Cooke cookedm+news at physics.mcmaster.ca
Thu Apr 7 16:34:19 EDT 2005


Chris Fonnesbeck <fonnesbeck at gmail.com> writes:

> I have been developing a python module for Markov chain Monte Carlo
> estimation, in which I frequently compare variable values with a very
> large number, that I arbitrarily define as:
>
> inf = 1e10000
>
> However, on Windows (have tried on Mac, Linux) I get the following behaviour:
>
>>>> inf = 1e10000
>>>> inf
> 1.0
>
> while I would have expected:
>
> 1.#INF
>
> Smaller numbers, as expected, yield:
>
>>>> inf = 1e100
>>>> inf
> 1e+100
>
> Obviously, I cannot use the former to compare against large (but not
> infinite) numbers, at least not to get the result I expect. Has anyone
> seen this behaviour?

I don't do Windows, so I can't say this will work, but try

>>> inf = 1e308*2

I think your problem is how the number is being parsed; perhaps
Windows is punting on all those zeros? Computing the infinity may or
may not work, but it gets around anything happening in parsing.

Alternatively, if you have numarray installed (which you should
probably consider if you're doing numerical stuff ;-) you could use

>>> import numarray.ieeespecial
>>> numarray.ieeespecial.plus_inf
inf

(there's minus_inf, nan, plus_zero, and minus_zero also)

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca



More information about the Python-list mailing list