Commit ad203bcb authored by Andreas Eger's avatar Andreas Eger

fix floating point accuracy problem in Timestamp#to_f

`.quo` return the most exact devision which fixes accuracy problems for the
timestamp coercion
parent 455b61c6
......@@ -80,7 +80,7 @@ module Google
end
def to_f
self.seconds + (self.nanos.to_f / 1_000_000_000)
self.seconds + (self.nanos.quo(1_000_000_000))
end
end
......
......@@ -13,10 +13,15 @@ class TestWellKnownTypes < Test::Unit::TestCase
assert_equal Time.at(12345), ts.to_time
assert_equal 12345, ts.to_i
ts.from_time(Time.at(123456, 654321))
time = Time.at(123456, 654321)
ts.from_time(time)
assert_equal 123456, ts.seconds
assert_equal 654321000, ts.nanos
assert_equal Time.at(123456.654321), ts.to_time
assert_equal time, ts.to_time
time = Time.now
ts.from_time(time)
assert_equal time.to_f, ts.to_time.to_f
end
def test_duration
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment