Project

General

Profile

Actions

Bug #10512

closed

Time.at produces imprecise nsec values

Added by cheald (Chris Heald) over 9 years ago. Updated over 9 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.0preview1 (2014-09-17 trunk 47616) [x86_64-linux]
[ruby-core:66285]

Description

I'm working on improving JRuby parity with MRI, and I've found what I think is a bug in MRI and its test suite. test_time.rb, in test_at asserts:

assert_equal(199, Time.at(0.0000002).nsec)

This passes under MRI, but fails under JRuby, which produces (the correct) value of 200.

It looks like there is a precision issue in MRI which is causing this behavior:

2.2.0-preview1 :008 > Time.at(0.000000197).nsec
=> 197
2.2.0-preview1 :009 > Time.at(0.000000198).nsec
=> 197
2.2.0-preview1 :010 > Time.at(0.000000199).nsec
=> 198
2.2.0-preview1 :011 > Time.at(0.000000200).nsec
=> 199
2.2.0-preview1 :012 > Time.at(0.000000201).nsec
=> 201

First and foremost, why does MRI assert that Time.at(0.0000002).nsec == 199, rather than 200? Second, if this is not a bug, why not (so that I can make sure JRuby performs equivalently)?

Actions

Also available in: Atom PDF

Like0
Like0