From 55473aea5c14316c11d6b66f5800f53c8aece8bb Mon Sep 17 00:00:00 2001 From: gogotanaka Date: Thu, 5 Mar 2015 03:29:37 +0000 Subject: [PATCH] * math.c: refactoring: remove unnecessary variable d0 to unify code appearance. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 ++++++--- math.c | 73 +++++++++++++++++++++++++------------------------------ 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35db628443..d5ea67ed86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Mar 5 12:22:23 2015 Kazuki Tanaka + + * math.c: refactoring: remove unnecessary variable d0 to unify code + appearance. + Thu Mar 5 11:50:54 2015 Shugo Maeda * vm_eval.c (eval_string_with_cref): A binding should keep @@ -254,7 +259,7 @@ Tue Feb 24 22:58:48 2015 Nobuyoshi Nakada * complex.c (nucomp_mul): calculate as rotation in complex plane if matrix calculation resulted in NaN. -Tue Feb 24 21:45:39 2015 Kazuki Tanaka +Tue Feb 24 21:45:39 2015 Kazuki Tanaka * test/ruby/test_math.rb(test_cbrt): Add an assertion for Math.cbrt(1.0/0) and move #test_cbrt to more proper place. @@ -715,7 +720,7 @@ Sat Jan 31 12:06:23 2015 Scott Francis start up so that it will not clash with the heap space. [Fix GH-822] -Fri Jan 30 17:28:29 2015 gogotanaka +Fri Jan 30 17:28:29 2015 Kazuki Tanaka * math.c (num2dbl_with_to_f): make faster when Bignum passed by direct conversion using rb_big2dbl(). [Feature #10800] @@ -736,7 +741,7 @@ Thu Jan 29 20:28:25 2015 SHIBATA Hiroshi * tool/make-snapshot: removed md5 digest with package information -Thu Jan 29 10:41:52 2015 gogotanaka +Thu Jan 29 10:41:52 2015 Kazuki Tanaka * math.c (Get_Double): direct casting from Fixnum to double. [Feature #10785] diff --git a/math.c b/math.c index fc03b5b0d4..0ce948f8e1 100644 --- a/math.c +++ b/math.c @@ -216,13 +216,12 @@ math_tan(VALUE obj, VALUE x) static VALUE math_acos(VALUE obj, VALUE x) { - double d0, d; + double d; - d0 = Get_Double(x); + d = Get_Double(x); /* check for domain error */ - if (d0 < -1.0 || 1.0 < d0) domain_error("acos"); - d = acos(d0); - return DBL2NUM(d); + if (d < -1.0 || 1.0 < d) domain_error("acos"); + return DBL2NUM(acos(d)); } /* @@ -241,13 +240,12 @@ math_acos(VALUE obj, VALUE x) static VALUE math_asin(VALUE obj, VALUE x) { - double d0, d; + double d; - d0 = Get_Double(x); + d = Get_Double(x); /* check for domain error */ - if (d0 < -1.0 || 1.0 < d0) domain_error("asin"); - d = asin(d0); - return DBL2NUM(d); + if (d < -1.0 || 1.0 < d) domain_error("asin"); + return DBL2NUM(asin(d)); } /* @@ -370,13 +368,12 @@ math_tanh(VALUE obj, VALUE x) static VALUE math_acosh(VALUE obj, VALUE x) { - double d0, d; + double d; - d0 = Get_Double(x); + d = Get_Double(x); /* check for domain error */ - if (d0 < 1.0) domain_error("acosh"); - d = acosh(d0); - return DBL2NUM(d); + if (d < 1.0) domain_error("acosh"); + return DBL2NUM(acosh(d)); } /* @@ -416,16 +413,15 @@ math_asinh(VALUE obj, VALUE x) static VALUE math_atanh(VALUE obj, VALUE x) { - double d0, d; + double d; - d0 = Get_Double(x); + d = Get_Double(x); /* check for domain error */ - if (d0 < -1.0 || +1.0 < d0) domain_error("atanh"); + if (d < -1.0 || +1.0 < d) domain_error("atanh"); /* check for pole error */ - if (d0 == -1.0) return DBL2NUM(-INFINITY); - if (d0 == +1.0) return DBL2NUM(+INFINITY); - d = atanh(d0); - return DBL2NUM(d); + if (d == -1.0) return DBL2NUM(-INFINITY); + if (d == +1.0) return DBL2NUM(+INFINITY); + return DBL2NUM(atanh(d)); } /* @@ -647,14 +643,13 @@ math_log10(VALUE obj, VALUE x) static VALUE math_sqrt(VALUE obj, VALUE x) { - double d0, d; + double d; - d0 = Get_Double(x); + d = Get_Double(x); /* check for domain error */ - if (d0 < 0.0) domain_error("sqrt"); - if (d0 == 0.0) return DBL2NUM(0.0); - d = sqrt(d0); - return DBL2NUM(d); + if (d < 0.0) domain_error("sqrt"); + if (d == 0.0) return DBL2NUM(0.0); + return DBL2NUM(sqrt(d)); } /* @@ -862,12 +857,12 @@ math_gamma(VALUE obj, VALUE x) * impossible to represent exactly in IEEE 754 double which have * 53bit mantissa. */ }; - double d0, d; + double d; double intpart, fracpart; - d0 = Get_Double(x); + d = Get_Double(x); /* check for domain error */ - if (isinf(d0) && signbit(d0)) domain_error("gamma"); - fracpart = modf(d0, &intpart); + if (isinf(d) && signbit(d)) domain_error("gamma"); + fracpart = modf(d, &intpart); if (fracpart == 0.0) { if (intpart < 0) domain_error("gamma"); if (0 < intpart && @@ -875,8 +870,7 @@ math_gamma(VALUE obj, VALUE x) return DBL2NUM(fact_table[(int)intpart - 1]); } } - d = tgamma(d0); - return DBL2NUM(d); + return DBL2NUM(tgamma(d)); } /* @@ -896,17 +890,16 @@ math_gamma(VALUE obj, VALUE x) static VALUE math_lgamma(VALUE obj, VALUE x) { - double d0, d; + double d; int sign=1; VALUE v; - d0 = Get_Double(x); + d = Get_Double(x); /* check for domain error */ - if (isinf(d0)) { - if (signbit(d0)) domain_error("lgamma"); + if (isinf(d)) { + if (signbit(d)) domain_error("lgamma"); return rb_assoc_new(DBL2NUM(INFINITY), INT2FIX(1)); } - d = lgamma_r(d0, &sign); - v = DBL2NUM(d); + v = DBL2NUM(lgamma_r(d, &sign)); return rb_assoc_new(v, INT2FIX(sign)); }