Re: [Tutor] The '45' bug in round()

2007-03-20 Thread Dick Moores
At 11:00 AM 3/19/2007, Michael Hannon wrote: On Mon, Mar 19, 2007 at 03:04:03AM -0700, Dick Moores wrote: Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, print round(0.19945,4) 0.1994 . . . Comments, Tutors? Am I way out

Re: [Tutor] The '45' bug in round()

2007-03-20 Thread Michael Hannon
On Tue, Mar 20, 2007 at 04:09:49AM -0700, Dick Moores wrote: At 11:00 AM 3/19/2007, Michael Hannon wrote: On Mon, Mar 19, 2007 at 03:04:03AM -0700, Dick Moores wrote: Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, print

Re: [Tutor] The '45' bug in round()

2007-03-20 Thread Dick Moores
At 08:31 AM 3/20/2007, you wrote: On Tue, Mar 20, 2007 at 04:09:49AM -0700, Dick Moores wrote: At 11:00 AM 3/19/2007, Michael Hannon wrote: On Mon, Mar 19, 2007 at 03:04:03AM -0700, Dick Moores wrote: Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding

Re: [Tutor] The '45' bug in round()

2007-03-20 Thread Michael Hannon
On Tue, Mar 20, 2007 at 09:03:43AM -0700, Dick Moores wrote: . . . Well, perhaps this is something for me to think about, but if you had asked me to round 0.19945 to four decimal places, I would have told you the answer is 0.1994, i.e., the same answer that Python gives. Is this because

Re: [Tutor] The '45' bug in round()

2007-03-20 Thread Terry Carroll
On Tue, 20 Mar 2007, Dick Moores wrote: print round(0.19965, 4) 0.1997 (which rounds up to an odd number, 7) Now that's weird. It should (I say) round to .1996; not because 6 is even and 7 is not[1], but because 0.19965 is actually closer to 0.1996 than to 0.1997: 0.19965

Re: [Tutor] The '45' bug in round()

2007-03-20 Thread Dick Moores
At 02:24 PM 3/20/2007, Terry Carroll wrote: On Tue, 20 Mar 2007, Dick Moores wrote: print round(0.19965, 4) 0.1997 (which rounds up to an odd number, 7) Now that's weird. It should (I say) round to .1996; not because 6 is even and 7 is not[1], but because 0.19965 is actually closer to

Re: [Tutor] The '45' bug in round()

2007-03-20 Thread Terry Carroll
On Tue, 20 Mar 2007, Dick Moores wrote: So you're claiming there's a bug in round()? No. I'm very reluctant to slap the bug label on behavior that strikes me as anomalous. I've found a bug or two, but in most cases, it's far more likely to be working as designed, and the bug is in my

Re: [Tutor] The '45' bug in round()

2007-03-20 Thread Dick Moores
At 02:43 PM 3/20/2007, Terry Carroll wrote: On Tue, 20 Mar 2007, Dick Moores wrote: So you're claiming there's a bug in round()? No. I'm very reluctant to slap the bug label on behavior that strikes me as anomalous. I've found a bug or two, but in most cases, it's far more likely to be

[Tutor] The '45' bug in round()

2007-03-19 Thread Dick Moores
Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, print round(0.19945,4) 0.1994 For rounding of random samples of numbers between 0 and 1 ending in '45', the error ratio is about 0.041. Here are a few more examples: print

Re: [Tutor] The '45' bug in round()

2007-03-19 Thread Kent Johnson
Dick Moores wrote: Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, print round(0.19945,4) 0.1994 For rounding of random samples of numbers between 0 and 1 ending in '45', the error ratio is about 0.041. Here are a few more

Re: [Tutor] The '45' bug in round()

2007-03-19 Thread andrew clarke
On Mon, Mar 19, 2007 at 03:04:03AM -0700, Dick Moores wrote: Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, Garbage In, Garbage Out :-) Floating point numbers in Python (and other computer languages) are only an approximation:

Re: [Tutor] The '45' bug in round()

2007-03-19 Thread Dick Moores
At 03:29 AM 3/19/2007, Kent Johnson wrote: Dick Moores wrote: Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, print round(0.19945,4) 0.1994 For rounding of random samples of numbers between 0 and 1 ending in '45', the error ratio

Re: [Tutor] The '45' bug in round()

2007-03-19 Thread Kent Johnson
Dick Moores wrote: Kent, I did understand the points you made in that earlier thread. However, I'm unhappy with print round(0.19945,4) 0.1994 Am I the only one unhappy with this kind of rounding? IMO you are chasing a non-problem. In real-world use, you would probably not type in a

Re: [Tutor] The '45' bug in round()

2007-03-19 Thread Michael Hannon
On Mon, Mar 19, 2007 at 03:04:03AM -0700, Dick Moores wrote: Yesterday I was shocked, SHOCKED, to discover that round() is occasionally rounding incorrectly. For example, print round(0.19945,4) 0.1994 . . . Comments, Tutors? Am I way out in left field with this? I suggest you might