On Sat, 14 Sep 2002, Mike Stok wrote:

> In article <8248e2a3.0209141306.7677f2d3 / posting.google.com>,
> Michael Witrant wrote:
> 
> > Hello,
> > 
> > The following results look buggy. I tried with Ruby 1.6.7 and 1.7.2.
> > 
> > (Time.at(0) + .1).usec # => 100000
> > (Time.at(0) + .2).usec # => 200000
> > (Time.at(0) + .3).usec # => 299999
> > (Time.at(0) + .4).usec # => 400000
> 
> Smells like floating point arithmetic in action to me ... try
> 
> [0.1, 0.2, 0.3, 0.4, 0.5].each { |f|
>   puts '%.20f' % f
> }

This is not the whole story IMHO. You have to take rounding issues in
account. If ruby rounded the value to full microseconds in the usual way,
you would see 300000 instead of 299999. The precision of a double is still 
just enough to discriminate full microseconds in a date (when zero is 
1970/1/1 and proper rounding is applied).

I don't know for sure, but I suspect that ruby is always rounding down
dates and times by intention -- otherwise, what would happen to

Time.utc(1970,12,31,23,59,59,999999) + .9e-6

Rounding up the microseconds value may also alter everything else in the 
date, including the year. Would you want that?

  Tobias