[issue16609] random.random() / float() loses precision when passed to str()

2012-12-04 Thread Cal Leeming
New submission from Cal Leeming: Hello, Today I came up against a strange problem where collisions were being encountered after less than 1mil iterations when attempting to use random.random(). After much digging, the problem was because I was casting my float to a string, and this was

[issue16609] random.random() / float() loses precision when passed to str()

2012-12-04 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: http://docs.python.org/2/tutorial/floatingpoint.html -- nosy: +serhiy.storchaka resolution: - invalid status: open - pending ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16609

[issue16609] random.random() / float() loses precision when passed to str()

2012-12-04 Thread Cal Leeming
Cal Leeming added the comment: As stated before, I have already read this document. This ticket is specifically about making users aware of this behaviour in the form of a documentation update on the random.random() docs. The link you provided does not exactly make this very clear.

[issue16609] random.random() / float() loses precision when passed to str()

2012-12-04 Thread Mark Dickinson
Mark Dickinson added the comment: The `random` module docs are not the right place to add notes about general floating-point arithmetic behaviour. -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16609

[issue16609] random.random() / float() loses precision when passed to str()

2012-12-04 Thread Cal Leeming
Cal Leeming added the comment: Normally I would concur, but casting random.random() to a string is commonly used, and people aren't going to read the entire floating point arithmetic page to figure this out. And even if they do, that page still doesn't make it entirely obvious at first read.

[issue16609] random.random() / float() loses precision when passed to str()

2012-12-04 Thread R. David Murray
R. David Murray added the comment: In fact it has been changed. In Python3 you get: x = 0.88022393777095409 x 0.8802239377709541 str(x) '0.8802239377709541' Even in 2.7 you would get the above repr, not the one you showed. This is because 2.7 and 3.3 use the shortest repr described in

[issue16609] random.random() / float() loses precision when passed to str()

2012-12-04 Thread Cal Leeming
Cal Leeming added the comment: Many thanks for your lengthy response David. Sorry, my initial bug report stated it was Python 2.7. The tests I performed were actually on Python 2.6.6. I will take a look at how to contribute documentation updates, and once I've familiarized myself with it

[issue16609] random.random() / float() loses precision when passed to str()

2012-12-04 Thread Mark Dickinson
Mark Dickinson added the comment: It is notable that this behaviour isn't described anywhere that I can find in the library manual or the reference manual. As David says, it applies only to 2.7; in 3.2 and later, `str` and `repr` are identical. a glossary entry be added for 'floating