diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-11 16:38:28 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-11 16:38:28 +0000 |
commit | d8769bffe590bad0a9d65cb796c622fb819feeb2 (patch) | |
tree | ec0df365f99103a1647f95134b17574fdeabb50d /rational.c | |
parent | 75bf28bb42c51932b3ca8acc423860f84c3cc5bc (diff) |
rational.c: optimize Rational#**
* rational.c (nurat_expt): optimize Rational#**.
Author: Tadashi Saito <[email protected]>
* numeric.c (rb_float_pow): rename flo_pow() to rb_float_pow()
and remove static to be exporetd.
* internal.h (rb_int_pow, rb_float_pow): exported.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56725 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'rational.c')
-rw-r--r-- | rational.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/rational.c b/rational.c index 210a721b17..4592178b7f 100644 --- a/rational.c +++ b/rational.c @@ -966,6 +966,8 @@ f_odd_p(VALUE integer) return Qfalse; } +static VALUE nurat_to_f(VALUE self); + /* * call-seq: * rat ** numeric -> numeric @@ -1022,12 +1024,12 @@ nurat_expt(VALUE self, VALUE other) switch (FIX2INT(f_cmp(other, ZERO))) { case 1: - num = f_expt(dat->num, other); - den = f_expt(dat->den, other); + num = rb_int_pow(dat->num, other); + den = rb_int_pow(dat->den, other); break; case -1: - num = f_expt(dat->den, f_negate(other)); - den = f_expt(dat->num, f_negate(other)); + num = rb_int_pow(dat->den, rb_int_uminus(other)); + den = rb_int_pow(dat->num, rb_int_uminus(other)); break; default: num = ONE; @@ -1039,10 +1041,10 @@ nurat_expt(VALUE self, VALUE other) } else if (RB_TYPE_P(other, T_BIGNUM)) { rb_warn("in a**b, b may be too big"); - return f_expt(f_to_f(self), other); + return rb_float_pow(nurat_to_f(self), other); } else if (RB_TYPE_P(other, T_FLOAT) || RB_TYPE_P(other, T_RATIONAL)) { - return f_expt(f_to_f(self), other); + return rb_float_pow(nurat_to_f(self), other); } else { return rb_num_coerce_bin(self, other, id_expt); |