diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-11 15:55:30 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-11 15:55:30 +0000 |
commit | 06d701a1f0c5981a386458c55cccef9486819cb5 (patch) | |
tree | 307f02a0d50d4ffdb9e82df1c345d072527b2b14 /bignum.c | |
parent | 6feb1684f36c7b160eba6b68be43a6cad05e4c40 (diff) | |
download | ruby-06d701a1f0c5981a386458c55cccef9486819cb5.tar.gz |
rational.c: avoid needless object allocation with nurat_to_double
* rational.c (nurat_to_double): introduce to convert rational to double
without object allocation.
* rational.c (rb_rational_plus, nurat_{sub,mul,to_f}): rewrite by using
nurat_to_double.
* bignum.c (rb_big_fdiv_double): introduce to calculate fdiv and return
the result as a double value.
* bignum.c (big_fdiv{,_int,_float}): change the return types for
implementing rb_big_fdiv_double.
* bignum.c (rb_big_fdiv): rewrite by using rb_big_fdiv_double.
* numeric.c (rb_int_fdiv_double): introduce to calculate fdiv and return
the result as a double value.
* numeric.c (fix_fdiv_double): rewrite from fix_fdiv to return the
result as a double value.
* numeric.c (rb_int_fdiv): rewrite by using rb_int_fdiv_double.
* internal.h (rb_{big,int}_fdiv_double): exported.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 28 |
1 files changed, 17 insertions, 11 deletions
@@ -6090,7 +6090,7 @@ big_shift(VALUE x, long n) return x; } -static VALUE +static double big_fdiv(VALUE x, VALUE y, long ey) { #define DBL_BIGDIG ((DBL_MANT_DIG + BITSPERDIG) / BITSPERDIG) @@ -6108,14 +6108,14 @@ big_fdiv(VALUE x, VALUE y, long ey) #if SIZEOF_LONG > SIZEOF_INT { /* Visual C++ can't be here */ - if (l > INT_MAX) return DBL2NUM(INFINITY); - if (l < INT_MIN) return DBL2NUM(0.0); + if (l > INT_MAX) return INFINITY; + if (l < INT_MIN) return 0.0; } #endif - return DBL2NUM(ldexp(big2dbl(z), (int)l)); + return ldexp(big2dbl(z), (int)l); } -static VALUE +static double big_fdiv_int(VALUE x, VALUE y) { long l, ey; @@ -6127,7 +6127,7 @@ big_fdiv_int(VALUE x, VALUE y) return big_fdiv(x, y, ey); } -static VALUE +static double big_fdiv_float(VALUE x, VALUE y) { int i; @@ -6135,8 +6135,8 @@ big_fdiv_float(VALUE x, VALUE y) return big_fdiv(x, y, i - DBL_MANT_DIG); } -VALUE -rb_big_fdiv(VALUE x, VALUE y) +double +rb_big_fdiv_double(VALUE x, VALUE y) { double dx, dy; @@ -6154,14 +6154,20 @@ rb_big_fdiv(VALUE x, VALUE y) else if (RB_FLOAT_TYPE_P(y)) { dy = RFLOAT_VALUE(y); if (isnan(dy)) - return y; + return dy; if (isinf(dx)) return big_fdiv_float(x, y); } else { - return rb_num_coerce_bin(x, y, rb_intern("fdiv")); + return RFLOAT_VALUE(rb_num_coerce_bin(x, y, rb_intern("fdiv"))); } - return DBL2NUM(dx / dy); + return dx / dy; +} + +VALUE +rb_big_fdiv(VALUE x, VALUE y) +{ + return DBL2NUM(rb_big_fdiv_double(x, y)); } VALUE |