summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-02 07:50:16 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-02 07:50:16 (GMT)
commit3fe5402dfa4b16fe586baee9c6f7187c3a00268d (patch)
tree54b5b9d1f6957a604e8304bffbbeba8fcd0c9279 /math.c
parent274fa77e3f3620cbd496952f622e930ea6951f02 (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.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/math.c b/math.c
index 5ce16e8..25914ec 100644
--- a/math.c
+++ b/math.c
@@ -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);