math module for Decimals

Mark Dickinson dickinsm at gmail.com
Sun Jan 4 11:56:01 CET 2009


On Jan 4, 10:38 am, "alex goretoy" <aleksandr.gore... at gmail.com>
wrote:
> haha python-svn # python Lib/decimal.py
>   File "Lib/decimal.py", line 683
>     sign = 0 if _math.copysign(1.0, f) == 1.0 else 1
>               ^
> SyntaxError: invalid syntax
>
> Although, It may be only because I ran it through python 2.4.3

Ah yes, that's it:  the 'x if b else y' syntax wasn't
introduced until Python 2.5;  see

http://docs.python.org/dev/whatsnew/2.5.html#pep-308-conditional-expressions

for more.

Hmm.  Maybe we shouldn't be using this syntax in from_float, if it's
the only thing that prevents the trunk version of decimal.py from
being used with Python 2.4.  On the other hand, from_float isn't
going to work until 2.7 anyway, since it uses a whole bunch of
new stuff:  as_integer_ratio and copysign (both introduced in 2.6),
and bit_length (introduced in 2.7).

Mark



More information about the Python-list mailing list