ruby-changes:43571
From: nobu <ko1@a...>
Date: Tue, 12 Jul 2016 22:07:55 +0900 (JST)
Subject: [ruby-changes:43571] nobu:r55644 (trunk): math.c: get_double_rshift
nobu 2016-07-12 22:07:51 +0900 (Tue, 12 Jul 2016) New Revision: 55644 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55644 Log: math.c: get_double_rshift * math.c (get_double_rshift): extract bignum to double conversion with bit offset. Modified files: trunk/math.c Index: math.c =================================================================== --- math.c (revision 55643) +++ math.c (revision 55644) @@ -456,9 +456,8 @@ math_log(int argc, const VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/math.c#L456 } static double -math_log1(VALUE x) +get_double_rshift(VALUE x, size_t *pnumbits) { - double d; size_t numbits; if (RB_BIGNUM_TYPE_P(x) && BIGNUM_POSITIVE_P(x) && @@ -469,8 +468,16 @@ math_log1(VALUE x) https://github.com/ruby/ruby/blob/trunk/math.c#L468 else { numbits = 0; } + *pnumbits = numbits; + return Get_Double(x); +} + +static double +math_log1(VALUE x) +{ + size_t numbits; + double d = get_double_rshift(x, &numbits); - d = Get_Double(x); /* check for domain error */ if (d < 0.0) domain_error("log"); /* check for pole error */ @@ -511,19 +518,9 @@ extern double log2(double); https://github.com/ruby/ruby/blob/trunk/math.c#L518 static VALUE math_log2(VALUE obj, VALUE x) { - double d; size_t numbits; + double d = get_double_rshift(x, &numbits); - if (RB_BIGNUM_TYPE_P(x) && BIGNUM_POSITIVE_P(x) && - DBL_MAX_EXP <= (numbits = rb_absint_numwords(x, 1, NULL))) { - numbits -= DBL_MANT_DIG; - x = rb_big_rshift(x, SIZET2NUM(numbits)); - } - else { - numbits = 0; - } - - d = Get_Double(x); /* check for domain error */ if (d < 0.0) domain_error("log2"); /* check for pole error */ @@ -551,19 +548,9 @@ math_log2(VALUE obj, VALUE x) https://github.com/ruby/ruby/blob/trunk/math.c#L548 static VALUE math_log10(VALUE obj, VALUE x) { - double d; size_t numbits; + double d = get_double_rshift(x, &numbits); - if (RB_BIGNUM_TYPE_P(x) && BIGNUM_POSITIVE_P(x) && - DBL_MAX_EXP <= (numbits = rb_absint_numwords(x, 1, NULL))) { - numbits -= DBL_MANT_DIG; - x = rb_big_rshift(x, SIZET2NUM(numbits)); - } - else { - numbits = 0; - } - - d = Get_Double(x); /* check for domain error */ if (d < 0.0) domain_error("log10"); /* check for pole error */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/