Inconsistent float behaviour on "inf" - current state?

Peter Knörrich knoerrich at hagen-partner.de
Tue Jun 27 12:37:52 CEST 2006


Hello,

I've found another inconsistency, and looking through the
list archives I can find mentions of funky stuff like

print float('inf')

giving

Infanity

with Python 1.5.2 on Solaris 7 in 2001, and a couple closed bug
reports on why "float('inf')" isn't supported everywhere, and I
understand the underlying problem:

libc simply isn't that good - never mind standard - with regard to floats.

However, seeing how Python does a great job with long ints
by using something better than standard libc, I fail to see how
reliance on libc should be a reason not to provide at least consistency:

Why does conversion from a long constant not use the same
library function that conversion from a long string would use?

a = float(1234....298299300)    ->     OverflowError: long int too large  
to convert to float
a = float('1234....298299300')  ->     inf, which led to silly errors in  
SQL (table has no column 'inf')

a = inf                         ->     NameError: name 'inf' is not defined
a = float('inf')                ->     inf

Now, I could understand how that may need some changes on lexing
the source code, so I'm not actually opening more bugs having
found workarounds for my own troubles here (quality guys insisting
on entering silly numbers, hah, try that with a 50 character input
field limit!).

Still, I'm interested to hear what the current state of affairs is
on using possibly inconsistent libc for floats?

Bye,

Peter Knörrich




More information about the Python-list mailing list