[issue36622] Inconsistent exponent notation formatting

2019-04-14 Thread Mark Dickinson


Mark Dickinson  added the comment:

FWIW, here's where that "at least two digits" is encoded in the CPython source: 
https://github.com/python/cpython/blob/bf94cc7b496a379e1f604aa2e4080bb70ca4020e/Python/pystrtod.c#L1227

*If* we wanted to, it would be an easy change to get rid of the extra leading 
exponent zeros.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36622] Inconsistent exponent notation formatting

2019-04-14 Thread Mark Dickinson


Mark Dickinson  added the comment:

Indeed it's deliberate. When the Decimal type was introduced, the "at least two 
exponent digits" behaviour of float formatting was already long established. 
But the specification that the Decimal type was based on (and the extensive 
test cases from the same source) use the minimum number of exponent digits 
instead.

If we want to make the two things consistent, that means either deliberately 
introducing incompatibilities with the Decimal specification, or changing 
long-standing behaviour for float.

There's no reason in principle that we couldn't modify the float formatting to 
use a single digit in the exponent (assuming that exponent is smaller than 10 
in absolute value). I'd expect that that would upset more people than it would 
help, though.

My guess is that the "at least 2 digits" rule in C99 7.24.2 is there to make it 
easier to align tables of values formatted in scientific notation. I can't 
think of another reason for force at least two digits.

For your use-case, could you convert all `float` objects to `Decimal` objects 
before comparison? The float to Decimal conversion doesn't lose any information 
(unlike the reverse conversion).

Closing this as "not a bug". There's certainly room for proposing and 
discussing changes to the behaviour, but that's probably best done on the 
python-ideas mailing list rather than the bug tracker.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36622] Inconsistent exponent notation formatting

2019-04-14 Thread Stefan Krah


Stefan Krah  added the comment:

Yes, I'd think the decisions are deliberate.

Floats follow printf(), this is from the manual for 'e':

  "The exponent always contains at least two digits; if the value is zero, the 
exponent is 00."


And decimal follows the specification at 
http://speleotrove.com/decimal/ .


Of course Python's format() could decide to override the specification, but it 
would lead to more code complexity.

But I don't think that mixing float/decimal output is a common use case.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36622] Inconsistent exponent notation formatting

2019-04-13 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Seems this has tests at 
https://github.com/python/cpython/blob/830b43d03cc47a27a22a50d777f23c8e60820867/Lib/test/test_decimal.py#L941
 . I also noticed the below. Considering this is the behavior from 2.7 is it a 
conscious design decision?

>>> '{:.5e}'.format(1.23457e+8)
'1.23457e+08'
>>> '{:.5e}'.format(decimal.Decimal(1.23457e+8))
'1.23457e+8'

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36622] Inconsistent exponent notation formatting

2019-04-12 Thread Eric V. Smith


Change by Eric V. Smith :


--
nosy: +eric.smith, mark.dickinson, skrah

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue36622] Inconsistent exponent notation formatting

2019-04-12 Thread Sep Dehpour


New submission from Sep Dehpour :

Floats and Decimals have inconsistent exponent notation formatting:

>>> '{:.5e}'.format(Decimal('2.0001'))
'2.00010e+0'
>>> '{:.5e}'.format(2.0001)
'2.00010e+00'

This is causing issues for us since we use the scientific notation formatted 
string of numbers to compare them. Between decimals and floats, one produces 
'+0' while the other one produces '+00'

--
messages: 340136
nosy: seperman
priority: normal
severity: normal
status: open
title: Inconsistent exponent notation formatting
type: behavior
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com