[Python-bugs-list] [ python-Bugs-477221 ] abs and divmod act oddly with -0.0

noreply@sourceforge.net noreply@sourceforge.net
Thu, 01 Nov 2001 13:52:00 -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: Open
Resolution: None
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 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