Hm, you're right Jeremy. This makes sense... Check this out:

>> t = Time.now
=> 2014-07-14 20:41:47 +0200
>> Time.at(t.tv_sec, t.tv_usec) == t
=> true
>> Time.at(t.to_f) == t
=> false


On Monday, July 14, 2014 8:29:53 PM UTC+2, Jeremy Evans wrote:
>
> On Monday, July 14, 2014 10:47:21 AM UTC-7, Petr Kaleta wrote:
>>
>> Hey Jeremy,
>> I am running on jRuby 1.7.13. But still, this doesn't make any sense, why 
>> ruby is doing this :/
>>
>> I don't understand your point with rounding already rounded time. 
>> Basically I don't understand why ruby is converting 918000 to 917999.
>>
>
> It's not really converting 918000 to 917999.  It stores 1405341161.918000 
> in a binary floating point format, which doesn't exactly match the decimal 
> format you provided.  Example:
>
> '%0.15f' % 1405341161.918000
> => "1405341161.917999982833862"
>
> So that is the input you are giving to the Time.at method.  Internally, 
> ruby 1.9+ stores Time objects with nanosecond precision, so this gets 
> converted to 1405341161 seconds, 917999982 nanoseconds:
>
> Time.at(1405341161.918000).nsec
> => 917999982
>
> If you want to give an exact fractional value, use a rational:
>
> Time.at(1405341161 + Rational(918000, 1000000)).nsec
> => 918000000
>
> Do not work in a floating point form at any point in your computation if 
> you want exact results.  
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to