| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
On Thursday 19 June 2008, John Smith wrote:
> Due to the nature of floating point numbers and depending on the value of
> self.step, you may have a value just less than 1.0 on one step and a value
> greater than 1.0 on the next. Try adding:
>
> if (self.x> 1.0) self.x = 1.0;
>
> snafu
Indeed. Always try to do The Right Thing and design your code not to rely on
exact results from floating point, since it NEVER gives them. In your case,
don't use addition:
# don't do self.step = 1./self.seq
for i in range(start,end):
self.processedfiles += 1
#don't do self.x += self.step, instead do
self.x = 1.*self.processedfiles/(end-start)
self.progressbar.set_fraction(self.x)
while gtk.events_pending(): gtk.main_iteration()
Since self.processedfiles, end and start are all integers, the calculation for
self.x is now properly bounded. There are still rounding errors, but they
don't accumulate so they never become significant.
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list
[Home] [Foundations of GTK+ Development] [Yosemite News] [Yosemite Photos] [Yosemite Book Store] [PDAs] [Gimp's Home] [Epson FAQ] [Steve's Art]
![]() |
![]() |