1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
gogotanaka 2015-03-05 03:29:37 +00:00
parent f403624a6f
commit 55473aea5c
2 changed files with 41 additions and 43 deletions

View file

@ -1,3 +1,8 @@
Wed Mar 5 12:22:23 2015 Kazuki Tanaka <gogotanaka@ruby-lang.org>
* math.c: refactoring: remove unnecessary variable d0 to unify code
appearance.
Thu Mar 5 11:50:54 2015 Shugo Maeda <shugo@ruby-lang.org> Thu Mar 5 11:50:54 2015 Shugo Maeda <shugo@ruby-lang.org>
* vm_eval.c (eval_string_with_cref): A binding should keep * vm_eval.c (eval_string_with_cref): A binding should keep
@ -254,7 +259,7 @@ Tue Feb 24 22:58:48 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* complex.c (nucomp_mul): calculate as rotation in complex plane * complex.c (nucomp_mul): calculate as rotation in complex plane
if matrix calculation resulted in NaN. if matrix calculation resulted in NaN.
Tue Feb 24 21:45:39 2015 Kazuki Tanaka <mail@tanakakazuki.com> Tue Feb 24 21:45:39 2015 Kazuki Tanaka <gogotanaka@ruby-lang.org>
* test/ruby/test_math.rb(test_cbrt): Add an assertion for Math.cbrt(1.0/0) * test/ruby/test_math.rb(test_cbrt): Add an assertion for Math.cbrt(1.0/0)
and move #test_cbrt to more proper place. and move #test_cbrt to more proper place.
@ -715,7 +720,7 @@ Sat Jan 31 12:06:23 2015 Scott Francis <scott.francis@shopify.com>
start up so that it will not clash with the heap space. start up so that it will not clash with the heap space.
[Fix GH-822] [Fix GH-822]
Fri Jan 30 17:28:29 2015 gogotanaka <mail@tanakakazuki.com> Fri Jan 30 17:28:29 2015 Kazuki Tanaka <gogotanaka@ruby-lang.org>
* math.c (num2dbl_with_to_f): make faster when Bignum passed by * math.c (num2dbl_with_to_f): make faster when Bignum passed by
direct conversion using rb_big2dbl(). [Feature #10800] direct conversion using rb_big2dbl(). [Feature #10800]
@ -736,7 +741,7 @@ Thu Jan 29 20:28:25 2015 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* tool/make-snapshot: removed md5 digest with package information * tool/make-snapshot: removed md5 digest with package information
Thu Jan 29 10:41:52 2015 gogotanaka <mail@tanakakazuki.com> Thu Jan 29 10:41:52 2015 Kazuki Tanaka <gogotanaka@ruby-lang.org>
* math.c (Get_Double): direct casting from Fixnum to double. * math.c (Get_Double): direct casting from Fixnum to double.
[Feature #10785] [Feature #10785]

73
math.c
View file

@ -216,13 +216,12 @@ math_tan(VALUE obj, VALUE x)
static VALUE static VALUE
math_acos(VALUE obj, VALUE x) math_acos(VALUE obj, VALUE x)
{ {
double d0, d; double d;
d0 = Get_Double(x); d = Get_Double(x);
/* check for domain error */ /* check for domain error */
if (d0 < -1.0 || 1.0 < d0) domain_error("acos"); if (d < -1.0 || 1.0 < d) domain_error("acos");
d = acos(d0); return DBL2NUM(acos(d));
return DBL2NUM(d);
} }
/* /*
@ -241,13 +240,12 @@ math_acos(VALUE obj, VALUE x)
static VALUE static VALUE
math_asin(VALUE obj, VALUE x) math_asin(VALUE obj, VALUE x)
{ {
double d0, d; double d;
d0 = Get_Double(x); d = Get_Double(x);
/* check for domain error */ /* check for domain error */
if (d0 < -1.0 || 1.0 < d0) domain_error("asin"); if (d < -1.0 || 1.0 < d) domain_error("asin");
d = asin(d0); return DBL2NUM(asin(d));
return DBL2NUM(d);
} }
/* /*
@ -370,13 +368,12 @@ math_tanh(VALUE obj, VALUE x)
static VALUE static VALUE
math_acosh(VALUE obj, VALUE x) math_acosh(VALUE obj, VALUE x)
{ {
double d0, d; double d;
d0 = Get_Double(x); d = Get_Double(x);
/* check for domain error */ /* check for domain error */
if (d0 < 1.0) domain_error("acosh"); if (d < 1.0) domain_error("acosh");
d = acosh(d0); return DBL2NUM(acosh(d));
return DBL2NUM(d);
} }
/* /*
@ -416,16 +413,15 @@ math_asinh(VALUE obj, VALUE x)
static VALUE static VALUE
math_atanh(VALUE obj, VALUE x) math_atanh(VALUE obj, VALUE x)
{ {
double d0, d; double d;
d0 = Get_Double(x); d = Get_Double(x);
/* check for domain error */ /* 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 */ /* check for pole error */
if (d0 == -1.0) return DBL2NUM(-INFINITY); if (d == -1.0) return DBL2NUM(-INFINITY);
if (d0 == +1.0) return DBL2NUM(+INFINITY); if (d == +1.0) return DBL2NUM(+INFINITY);
d = atanh(d0); return DBL2NUM(atanh(d));
return DBL2NUM(d);
} }
/* /*
@ -647,14 +643,13 @@ math_log10(VALUE obj, VALUE x)
static VALUE static VALUE
math_sqrt(VALUE obj, VALUE x) math_sqrt(VALUE obj, VALUE x)
{ {
double d0, d; double d;
d0 = Get_Double(x); d = Get_Double(x);
/* check for domain error */ /* check for domain error */
if (d0 < 0.0) domain_error("sqrt"); if (d < 0.0) domain_error("sqrt");
if (d0 == 0.0) return DBL2NUM(0.0); if (d == 0.0) return DBL2NUM(0.0);
d = sqrt(d0); return DBL2NUM(sqrt(d));
return DBL2NUM(d);
} }
/* /*
@ -862,12 +857,12 @@ math_gamma(VALUE obj, VALUE x)
* impossible to represent exactly in IEEE 754 double which have * impossible to represent exactly in IEEE 754 double which have
* 53bit mantissa. */ * 53bit mantissa. */
}; };
double d0, d; double d;
double intpart, fracpart; double intpart, fracpart;
d0 = Get_Double(x); d = Get_Double(x);
/* check for domain error */ /* check for domain error */
if (isinf(d0) && signbit(d0)) domain_error("gamma"); if (isinf(d) && signbit(d)) domain_error("gamma");
fracpart = modf(d0, &intpart); fracpart = modf(d, &intpart);
if (fracpart == 0.0) { if (fracpart == 0.0) {
if (intpart < 0) domain_error("gamma"); if (intpart < 0) domain_error("gamma");
if (0 < intpart && if (0 < intpart &&
@ -875,8 +870,7 @@ math_gamma(VALUE obj, VALUE x)
return DBL2NUM(fact_table[(int)intpart - 1]); return DBL2NUM(fact_table[(int)intpart - 1]);
} }
} }
d = tgamma(d0); return DBL2NUM(tgamma(d));
return DBL2NUM(d);
} }
/* /*
@ -896,17 +890,16 @@ math_gamma(VALUE obj, VALUE x)
static VALUE static VALUE
math_lgamma(VALUE obj, VALUE x) math_lgamma(VALUE obj, VALUE x)
{ {
double d0, d; double d;
int sign=1; int sign=1;
VALUE v; VALUE v;
d0 = Get_Double(x); d = Get_Double(x);
/* check for domain error */ /* check for domain error */
if (isinf(d0)) { if (isinf(d)) {
if (signbit(d0)) domain_error("lgamma"); if (signbit(d)) domain_error("lgamma");
return rb_assoc_new(DBL2NUM(INFINITY), INT2FIX(1)); return rb_assoc_new(DBL2NUM(INFINITY), INT2FIX(1));
} }
d = lgamma_r(d0, &sign); v = DBL2NUM(lgamma_r(d, &sign));
v = DBL2NUM(d);
return rb_assoc_new(v, INT2FIX(sign)); return rb_assoc_new(v, INT2FIX(sign));
} }