Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

> I wouldn't trust a language behaving crazy like this

I guess then you won't trust C, Java, C++, Swift, Javascript, Ruby, Cobol, 
Fortran, and pretty much every programming language in existence. The only ones 
that escape this are ones that don't have floating point numbers at all.


> you haven't tried it on 2.7 did you ?

We know how Python 2.7 works. Some of us have been using Python for 25 years, 
since version 1.5 or older. Do you think you are the first person to have 
noticed this? There are hundreds of thousands of Python programmers, believe me 
you're not the first, or even the ten-thousandth person to have noticed.

Python 2.7 rounds off the default display of floats to make them look "pretty" 
instead of displaying their actual value. Try this in 2.7 and see what happens:

i=0
while i < 1.2:
    i += 0.1
    print "default:", i, "actual: %.24f" % i

The calculations are *precisely* the same, only the display is different.

Honestly Mike, this is not a Python issue, it is universal to all languages 
with fixed-size floating point numbers. This is not a bug, it is how numeric 
computing works *everywhere*. People write peer reviewed scientific papers 
about this:

http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.22.6768

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html


If you want to educate yourself on the issue, rather than just rant about not 
trusting the language and abuse people who have been using the language for 
decades, you could do a lot worse than to start here:

https://randomascii.wordpress.com/2012/05/20/thats-not-normalthe-performance-of-odd-floats/

https://randomascii.wordpress.com/2012/04/05/floating-point-complexities/

and take careful note that the author talks about C, probably the most common, 
fundamental and trusted programming language in the world. (Also remember that 
when Bruce Dawson talks about floats in C, they are half the precision of 
Python floats, which are C doubles.)

The bottom line is that floats are not the infinitely precise exact 
mathematical numbers we learn about in school, they are more like the numbers 
you get on a calculator.

----------
nosy: +steven.daprano

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40981>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to