From: GOTO Kentaro Date: 2002-09-16T10:49:47+09:00 Subject: Re: Time#+ and usec At Sun, 15 Sep 2002 09:02:57 +0900, Michael Campbell wrote: > > (Time.at(0) + .1).usec # => 100000 > > (Time.at(0) + .2).usec # => 200000 > > (Time.at(0) + .3).usec # => 299999 > > (Time.at(0) + .4).usec # => 400000 > > Looks to me like your standard "base 10 numbers can't necessarily be > represented exactly in a base 2 system" issue. Yep. For example, % ruby -rieee754hack -e'[0.1,0.2,0.3,0.4,0.5].each{|i| puts i.human_readable}' +1 * 0b1.1001100110011001100110011001100110011001100110011010 * 2**(1019-1023) +1 * 0b1.1001100110011001100110011001100110011001100110011010 * 2**(1020-1023) +1 * 0b1.0011001100110011001100110011001100110011001100110011 * 2**(1021-1023) +1 * 0b1.1001100110011001100110011001100110011001100110011010 * 2**(1021-1023) +1 * 0b1.0000000000000000000000000000000000000000000000000000 * 2**(1022-1023) % But my FreeBSD box reports 100000, 200000, 300000 and 400000 for (Time.at(0)+0.1).usec etc. The result seems to depend on the implementation of modf(3) which is used in time.c:time_plus(). -- Gotoken