[Python-ideas] Changing Decimal.__pos__ and Decimal.__neg__ [Was: Re: Python Numbers as Human Concept Decimal System]
Tim Peters
tim.peters at gmail.com
Mon Mar 10 20:08:49 CET 2014
[Mark Dickinson <dickinsm at gmail.com>]
>> >>> -Decimal(0.0) # negative sign mysteriously disappears.
>>
>> Decimal('0')
[Stefan Krah <stefan at bytereef.org>]
> Unless the rounding mode is ROUND_FLOOR. :(
>
> >>> getcontext().rounding = ROUND_FLOOR
> >>> -Decimal(0.0)
> Decimal('-0')
I may be missing something, but our docs don't appear to be clear
about what unary minus means in Python's decimal implementation.
Looks like Mike C's intent was that
+x
act like
Decimal(0) + x
and
-x
like
Decimal(0) - x
Then all the examples "make sense" (given that you think the
standards' rules for adding/subtracting signed zeros make sense).
Can't win! That -x loses the sign when x is a positive 0 (under most
rounding modes) is jarring; but that the results of "-x" and "0-x" may
not be the same would also be jarring.
Not a fan of signed zeroes :-(
More information about the Python-ideas
mailing list