summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-28 14:25:59 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-28 14:25:59 (GMT)
commit202cc8e615975d67659d517bac04b8697c34c2f0 (patch)
tree0abf4de8dc11901483e22c662b0f8ce66d85f137 /math.c
parentf450dede0e71b0db8ec0ba2f31f6907a778e3fbb (diff)
math.c: fix for Bignum argument
* math.c (math_log, math_log2, math_log10): fix for Bignum argument. numbits should be add only when right shifted. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r--math.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/math.c b/math.c
index d9c7633..e621d1a 100644
--- a/math.c
+++ b/math.c
@@ -442,7 +442,7 @@ math_log(int argc, VALUE *argv)
{
VALUE x, base;
double d0, d;
- size_t numbits = 0;
+ size_t numbits;
rb_scan_args(argc, argv, "11", &x, &base);
@@ -451,6 +451,9 @@ math_log(int argc, VALUE *argv)
numbits -= DBL_MANT_DIG;
x = rb_big_rshift(x, SIZET2NUM(numbits));
}
+ else {
+ numbits = 0;
+ }
Need_Float(x);
d0 = RFLOAT_VALUE(x);
@@ -501,13 +504,16 @@ static VALUE
math_log2(VALUE obj, VALUE x)
{
double d0, d;
- size_t numbits = 0;
+ size_t numbits;
if (RB_BIGNUM_TYPE_P(x) && RBIGNUM_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;
+ }
Need_Float(x);
d0 = RFLOAT_VALUE(x);
@@ -540,13 +546,16 @@ static VALUE
math_log10(VALUE obj, VALUE x)
{
double d0, d;
- size_t numbits = 0;
+ size_t numbits;
if (RB_BIGNUM_TYPE_P(x) && RBIGNUM_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;
+ }
Need_Float(x);
d0 = RFLOAT_VALUE(x);