weird float() behavior

Eugene Pervago pervago at prodigy.net.mx
Mon Mar 31 22:37:40 EST 2003


pball at umich.edu (pball) wrote in message news:<a7a97e2d.0303302128.20a2abf5 at posting.google.com>...
> Hi,
> 
> so I had a confusion with int() (why an exception for int('3.1416')?
> why not just return 3? ok, I read threads from many years ago) and
> float(). I've been sifting through the c.l.py archives, but this seems
> new.  Basically, int(float(someString)) seems always to return zero
> with a particular mix of gcc and python versions.
> 
> (note carefully the machine name, gcc & python versions)
> 
> [pball at wylbur]% python
> Python 2.2.2 (#1, Mar 29 2003, 23:20:21)
> [GCC 3.2.2 20030322 (Gentoo Linux 1.4 3.2.2-r2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> s = '16073.0'
> >>> int( float(s) ) 0
> >>>
> 
[snip]
> 
> [pball at wylbur]% python                                                
>  ~
> Python 2.2.2 (#1, Mar 29 2003, 23:20:21)
> [GCC 3.2.2 20030322 (Gentoo Linux 1.4 3.2.2-r2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> s = '3.1415' 
> >>> int( float(s) ) -610
> >>> int( 3.1416 ) 0
> >>> int( 3.1415 ) -610
> >>> int( 3.1417 ) 0
> >>> int( 3.1419 )
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> OverflowError: float too large to convert
> >>>
> 
> Ok, that's enough.  Has anyone else seen this?  Any ideas how I broke
> it so completely? Is there more info I can post to better identify it?
> Is there a regression test we could add to the post-compile process to
> flag this?
> 
> Thanks - PB.

Let me guess, your CFLAGS (system-global compiler options for
non-Gentoo folks) include -march=pentium4? GCC 3.2.2 and
-march=pentium4 generate broken code for integer conversion (the
culprit is actually -msse2 which is enabled by the above option)

http://forums.gentoo.org/viewtopic.php?t=39202

Eugene Pervago




More information about the Python-list mailing list