Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Steven D'Aprano
Kĩnũthia Mũchane wrote: On 06/12/2011 08:13 PM, Steven D'Aprano wrote: Unfortunately, many common fractions cannot be written exactly in binary. You're probably familiar with the fact that fractions like 1/3 cannot be written exactly in decimal: 1/3 = 0.... goes on forever Does it?

Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Kĩnũthia Mũchane
On 06/12/2011 08:13 PM, Steven D'Aprano wrote: Ryan Strunk wrote: Hi everyone, I'm designing a timeline. When the user presses the right arrow, 0.1 is added to the current position. The user can add events to the timeline, and can later scroll back across those events to see what they are. But

Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Válas Péter
2011/6/13 Steven D'Aprano > Okay fine, so "1024" stored as a number only requires 10 bits (binary >>> digits) to store, >>> >> >> Actually, 11. :-) >> > > > I see your smiley, but actually more than that. OK, this was the math, I just told that 10 bits were not enough for 2^10. > > And if you'

Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Steven D'Aprano
Válas Péter wrote: 2011/6/12 Brett Ritter Okay fine, so "1024" stored as a number only requires 10 bits (binary digits) to store, Actually, 11. :-) I see your smiley, but actually more than that. Due to the way computers are designed, numbers are stored in fixed bundles of 8 bits making a

Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Steven D'Aprano
Nathan wrote: who can tell me how to unsubscribe the message. Look at the bottom of every single message to the mailing list, and you will see this: Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor -- Steven _

Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Válas Péter
2011/6/12 Brett Ritter > > Okay fine, so "1024" stored as a number only requires 10 bits (binary > digits) to store, Actually, 11. :-) Another point that was still not emphasized enough: that's why Python's documentation at http://docs.python.org/dev/library/stdtypes.html#mapping-types-dict say

Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Alan Gauld
"Nathan" wrote Every message tells you: who can tell me how to unsubscribe the message. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor --

Re: [Tutor] Floating Point Craziness

2011-06-13 Thread Nathan
who can tell me how to unsubscribe the message. At 2011-06-13 01:13:05,"Steven DAprano" wrote: >Ryan Strunk wrote: >> Hi everyone, >> I'm designing a timeline. When the user presses the right arrow, 0.1 is >> added to the current position. The user can add events to the timeline, and >> can l

Re: [Tutor] Floating Point Craziness

2011-06-12 Thread Steven D'Aprano
Ryan Strunk wrote: Hi everyone, I'm designing a timeline. When the user presses the right arrow, 0.1 is added to the current position. The user can add events to the timeline, and can later scroll back across those events to see what they are. But something I absolutely don't understand is happen

Re: [Tutor] Floating Point Craziness

2011-06-12 Thread Brett Ritter
> dictionary = {3.1014: value, 2.1005: value, > 1.0999: value} > Why is this happening? The output is telling me 3.1, but the value isn't It's a quirk of how computers store floating point numbers. While humans mentally tend to treat everything as characters (a

[Tutor] Floating Point Craziness

2011-06-12 Thread Ryan Strunk
Hi everyone, I'm designing a timeline. When the user presses the right arrow, 0.1 is added to the current position. The user can add events to the timeline, and can later scroll back across those events to see what they are. But something I absolutely don't understand is happening: I used the progr