Message31479
The identification of -0.0 and 0.0 in scripts leads to some surprising
results. In particular, code that behaves one way in the interpreter can behave differently in a script. For example:
Python 2.6a0 (trunk:54183M, Mar 6 2007, 20:16:00)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from math import atan2;
>>> x = -0.
>>> y = 0.
>>> print atan2(y, -1.)
3.14159265359
But:
>>> exec("from math import atan2; x = -0.; y = 0.; print atan2(y, -1.)")
-3.14159265359
A simpler example:
>>> x, y = -0., 0.
>>> x, y
(-0.0, -0.0)
>>> id(x) == id(y)
True
But:
>>> x = -0.
>>> y = 0.
>>> x, y
(-0.0, 0.0)
This occurs both on SuSE Linux 9.3/i686 and on OS X 10.4.8/PowerPC.
|
|
Date |
User |
Action |
Args |
2007-08-23 14:52:24 | admin | link | issue1678380 messages |
2007-08-23 14:52:24 | admin | create | |
|