Loss of precision / data corruption with Tkinter.DoubleVar ?!

Dan Bishop danb_83 at yahoo.com
Fri Apr 11 17:49:39 EDT 2003


fnord at u.washington.edu (Lonnie Princehouse) wrote in message news:<f70e3538.0304111007.b0a72c3 at posting.google.com>...
> Greetings, 
> 
> I stumbled across this curiosity yesterday:
> 
> >>> x = 0.33333333333333098
> >>> x
>  0.33333333333333098     
> >>> import Tkinter
> >>> y = Tkinter.DoubleVar(Tkinter.Tk())
> >>> y.set(x)
> >>> y.get()
> 0.33333333333300003  
> 
> What the....?
> 
> Sure, it's only on the order of 10e-13 delta, 
> but why is there any difference at all??

It looks like Tkinter.DoubleVar stores numbers in decimal floating
point (with 12 digits of precision) instead of binary like it ought
to.  Notice that you do get the correct result when x is (as close as
possible to) a power of 0.1.




More information about the Python-list mailing list