[Python-bugs-list] [ python-Bugs-477221 ] abs and divmod act oddly with -0.0
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 01 Nov 2001 15:15:13 -0800
Bugs item #477221, was opened at 2001-11-01 10:40
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=477221&group_id=5470
Category: Python Interpreter Core
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Tim Peters (tim_one)
Summary: abs and divmod act oddly with -0.0
Initial Comment:
Python 2.1.1 (#97, Aug 2 2001, 21:53:31) [CW PPC GUSI2 THREADS] on mac
Type "copyright", "credits" or "license" for more information.
>>> abs(-1.0)
1.0
>>> abs(-0.0)
-0.0
>>> divmod(-0.0, 1.0)
(0.0, -0.0)
The same thing happens on a unix Python 2.0, so I think it's pretty generic. I hope folks think it's a bug, not a feature, and worth fixing. It bit me when trying to write a sexagesimal formatter -- output that should have shown -0:00:00 showed 0:00:-0 instead.
-- Russell
Russell Owen
owen@astro.washington.edu
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2001-11-01 15:15
Message:
Logged In: YES
user_id=31435
divmod(-0., 1.) should return (-0.0, +0.0) across platforms
now, although the minus sign may not *display* across
platforms (does not on Windows, probably does on most Unix
flavors).
This was something of a nightmare, as it turned out the
underlying libm fmod() gives different results across
platforms in the presence of signed zeroes.
Objects/floatobject.c; new revision: 2.105
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-11-01 13:52
Message:
Logged In: YES
user_id=31435
And abs(float) was fixed again <wink>, in
Objects/floatobject.c new revision: 2.104
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-11-01 12:11
Message:
Logged In: YES
user_id=31435
abs(-0.0) returns +0.0, as of
Objects/floatobject.c; new revision: 2.103
Haven't looked at divmod yet.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-11-01 11:16
Message:
Logged In: YES
user_id=31435
A bit of a dilemma here. Python doesn't know anything
about signed zeroes, and there's really no portable way in
C to detect one when it happens (until C99 is universally
implemented). Even that you're getting "-0.0" output is a
platform-dependent accident (it depends on what the
platform C sprintf does; and, e.g., on Windows it does not
display a leading minus sign).
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=477221&group_id=5470