Monday 15 March 2010

Infinity generated in python code -


I'm looking at some complex Python 2.6 code that sometimes creates infinity (at least one infinite serial Is being done by Jason Library - which checks w / math.isinf.)

What is particularly troubling is that the result of calculating Python (as far as I can) Countless should not be able to set up. Am I wrong with this assumption? I knew that you can only achieve infinity by constants:

  k = float ('inf') k = 1e900  

Floats exceeds the accuracy anywhere between 1e308 and 1e30 9, so if you are calculating the result above that limit, you will see

  & gt; & Gt; & Gt; 1e308 1e + 308 & gt; & Gt; & Gt; 1e309 inf & gt; & Gt; & Gt; Json.dumps (1e308, allow_nan = false) '1e + 308' & gt; & Gt; & Gt; Json.dumps (1e30 9, allow_nan = False) traceback (most recent call final): File "& lt; stdin>", line 1, & lt; Module & gt; File "/usr/lib/python2.6/json/__init__.py", line 237, dump ** KW) .encode (obj) file "/usr/lib/python2.6/json/encoder.py", line 367, encode in the divisions = list (self.iterencode (o)) file "/usr/lib/python2.6/json/encoder.py", line 304, _iterencode yield floatstr (o, manually / usr / Raise valueError (msg) ValueError: float value JSON not out of range are not compliant: inf>   

can handle decimal large numbers, but clearly a performance penalty (and it is not sorted with JSN Can be done only)

 > Decimal & gt; & gt; & gt; decimal ('1e 9 00') by decimal import / 10 decimal ( "1 e + 89 9")  

Here is an additional example that does not increase the overflow exception

 >  

A = 1e308>> A + an inf


No comments:

Post a Comment