From 841cf3b9488c0e7ea23b92acbb9078dee3347deb Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 1 Jul 2009 20:38:57 +0000 Subject: [PATCH] * time.c (num_exact): use to_r for T_FLOAT. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ time.c | 49 +------------------------------------------------ 2 files changed, 5 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a8e614e8f..0e066755b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Jul 2 05:37:38 2009 Tanaka Akira + + * time.c (num_exact): use to_r for T_FLOAT. + Thu Jul 2 05:15:54 2009 Tanaka Akira * time.c (quo): return an integer if possible. diff --git a/time.c b/time.c index 09afb57be5..95c64a8b8d 100644 --- a/time.c +++ b/time.c @@ -154,55 +154,8 @@ num_exact(VALUE v) break; case T_FLOAT: - { - double d = NUM2DBL(v); - int exp; - static long r = 0; - static int n = 0; - if (r == 0) { - long rr = FLT_RADIX; - int nn = 1; - while (rr < FIXNUM_MAX / FLT_RADIX) { - rr *= FLT_RADIX; - nn++; - } - n = nn; - r = rr; - } - d = frexp(d, &exp); - v = INT2FIX(0); - while (d != 0) { - long u; - exp -= n; - d *= r; - v = mul(v, LONG2FIX(r)); - u = (long)d; - d -= u; - v = add(v, LONG2FIX(u)); - } - if (exp < 0) { - VALUE w; - w = INT2FIX(1); - if (FLT_RADIX == 2) - w = lshift(w, INT2FIX(-exp)); - else - while (exp) { - w = mul(w, INT2FIX(FLT_RADIX)); - exp++; - } - v = quo(v, w); - } - else { - if (FLT_RADIX == 2) - v = lshift(v, INT2FIX(exp)); - else - while (exp) { - v = mul(v, INT2FIX(FLT_RADIX)); - exp--; - } - } + v = rb_convert_type(v, T_RATIONAL, "Rational", "to_r"); break; - } case T_NIL: goto typeerror;