Why the false in the 2nd comparison? I am not loading any libraries.
puts RUBY_DESCRIPTION
t = Time.now
t1 = Time.at(t.to_f)
t2 = Time.at(t.to_f)
puts( t1 == t2 )
puts( t == t1 )
puts( t.to_f == t1.to_f )
printf "%.64f\n%.64f\n%.64f\n", t, t1, t2
Output:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
true
false
true
1347661545.4348440170288085937500000000000000000000000000000000000000000000
1347661545.4348440170288085937500000000000000000000000000000000000000000000
1347661545.4348440170288085937500000000000000000000000000000000000000000000
I get all trues on 1.8.7. What’s going on?
I updated the script to show that the floats are the same, as far as I can tell. Am I missing something?
From the docs on Time.to_f: “Note that IEEE 754 double is not accurate enough to represent number of nanoseconds from the Epoch.” To illustrate @oldrinb’s comment:
Time#subsec documentation: “The lowest digit of #to_f and subsec is different because IEEE 754 double is not accurate enough to represent the rational. The accurate value is returned by subsec.”