diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-02 07:50:16 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-02 07:50:16 +0000 |
commit | 3fe5402dfa4b16fe586baee9c6f7187c3a00268d (patch) | |
tree | 54b5b9d1f6957a604e8304bffbbeba8fcd0c9279 /math.c | |
parent | 274fa77e3f3620cbd496952f622e930ea6951f02 (diff) |
* math.c (math_gamma): get rid of direct comparison between too
big double and integer, with gcc on x86_64. [ruby-core:25257]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24738 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r-- | math.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -13,6 +13,8 @@ #include <math.h> #include <errno.h> +#define numberof(array) (int)(sizeof(array) / sizeof((array)[0])) + VALUE rb_mMath; extern VALUE rb_to_float(VALUE val); @@ -663,13 +665,14 @@ math_gamma(VALUE obj, VALUE x) }; double d0, d; double intpart, fracpart; + int n; Need_Float(x); d0 = RFLOAT_VALUE(x); fracpart = modf(d0, &intpart); if (fracpart == 0.0 && - 0 < intpart && - (size_t)intpart <= sizeof(fact_table)/sizeof(*fact_table)) { - return DBL2NUM(fact_table[(int)intpart - 1]); + 0 < intpart && + (n = (int)intpart - 1) < numberof(fact_table)) { + return DBL2NUM(fact_table[n]); } errno = 0; d = tgamma(d0); |