diff options
author | gogotanaka <gogotanaka@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-03-14 11:07:49 +0000 |
---|---|---|
committer | gogotanaka <gogotanaka@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-03-14 11:07:49 +0000 |
commit | 0e749ddedc100e88dad9fb367ade2e56bbf8f785 (patch) | |
tree | 2aa5804c3ea6585943b28993627e1b30a5a3dddb /math.c | |
parent | ffe896c3cb0872baf301a5c21b90059f33d3d7a0 (diff) |
* math.c (math_gamma): optimization for passed small integer.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r-- | math.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -836,6 +836,8 @@ mingw_tgamma(const double d) * */ +#define NGAMMA_TABLE 23 + static VALUE math_gamma(VALUE obj, VALUE x) { @@ -868,16 +870,13 @@ math_gamma(VALUE obj, VALUE x) * 53bit mantissa. */ }; double d; - double intpart, fracpart; d = Get_Double(x); /* check for domain error */ 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 && - intpart - 1 < (double)numberof(fact_table)) { - return DBL2NUM(fact_table[(int)intpart - 1]); + if (d == floor(d)) { + if (d < 0.0) domain_error("gamma"); + if (1.0 <= d && d <= NGAMMA_TABLE) { + return DBL2NUM(fact_table[(int)d - 1]); } } return DBL2NUM(tgamma(d)); |