mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* time.c (rb_time_unmagnify_to_float): Avoid double rounding.
Reported by Tsuyoshi Sawada. https://bugs.ruby-lang.org/issues/10135#note-1 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47289 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
febf2cefb3
commit
092c647cb7
3 changed files with 16 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
Tue Aug 26 20:46:55 2014 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* time.c (rb_time_unmagnify_to_float): Avoid double rounding.
|
||||
Reported by Tsuyoshi Sawada.
|
||||
https://bugs.ruby-lang.org/issues/10135#note-1
|
||||
|
||||
Tue Aug 26 17:12:47 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* io.c (io_close): ignore only "closed stream" IOError and
|
||||
|
|
|
@ -423,6 +423,12 @@ class TestTime < Test::Unit::TestCase
|
|||
assert_equal(946684800.0, t2000.to_f)
|
||||
end
|
||||
|
||||
def test_to_f_accuracy
|
||||
# https://bugs.ruby-lang.org/issues/10135#note-1
|
||||
f = 1381089302.195
|
||||
assert_equal(f, Time.at(f).to_f, "[ruby-core:64373] [Bug #10135] note-1")
|
||||
end
|
||||
|
||||
def test_cmp
|
||||
t2000 = get_t2000
|
||||
assert_equal(-1, t2000 <=> Time.gm(2001))
|
||||
|
|
5
time.c
5
time.c
|
@ -697,7 +697,10 @@ rb_time_unmagnify_to_float(wideval_t w)
|
|||
}
|
||||
#endif
|
||||
v = w2v(w);
|
||||
return quo(v, DBL2NUM(TIME_SCALE));
|
||||
if (RB_TYPE_P(v, T_RATIONAL))
|
||||
return rb_Float(quo(v, INT2FIX(TIME_SCALE)));
|
||||
else
|
||||
return quo(v, DBL2NUM(TIME_SCALE));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue