mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* rational.c (float_to_r): an improvement.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a7290749a5
commit
bb45f1b2b8
2 changed files with 20 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
|||
Sun Jul 19 22:22:54 2009 Tadayoshi Funaba <tadf@dotrb.org>
|
||||
|
||||
* rational.c (float_to_r): an improvement.
|
||||
|
||||
Sun Jul 19 20:41:24 2009 Tadayoshi Funaba <tadf@dotrb.org>
|
||||
|
||||
* complex.c (make_patterns): do not use \d.
|
||||
|
|
16
rational.c
16
rational.c
|
@ -1695,6 +1695,9 @@ float_decode(VALUE self)
|
|||
}
|
||||
#endif
|
||||
|
||||
#define id_lshift rb_intern("<<")
|
||||
#define f_lshift(x,n) rb_funcall(x, id_lshift, 1, n)
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* flt.to_r -> rational
|
||||
|
@ -1717,7 +1720,20 @@ float_to_r(VALUE self)
|
|||
VALUE f, n;
|
||||
|
||||
float_decode_internal(self, &f, &n);
|
||||
#if FLT_RADIX == 2
|
||||
{
|
||||
long ln = FIX2LONG(n);
|
||||
|
||||
if (ln == 0)
|
||||
return f_to_r(f);
|
||||
if (ln > 0)
|
||||
return f_to_r(f_lshift(f, n));
|
||||
ln = -ln;
|
||||
return rb_rational_new2(f, f_lshift(ONE, INT2FIX(ln)));
|
||||
}
|
||||
#else
|
||||
return f_to_r(f_mul(f, f_expt(INT2FIX(FLT_RADIX), n)));
|
||||
#endif
|
||||
}
|
||||
|
||||
static VALUE rat_pat, an_e_pat, a_dot_pat, underscores_pat, an_underscore;
|
||||
|
|
Loading…
Add table
Reference in a new issue