summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-22 04:56:24 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-22 04:56:24 (GMT)
commit05ee7f2fdbb63ba33aaf5abb814b6166277b5060 (patch)
tree58e9e0cc724488448f7189a4e22f73bf950573f9 /numeric.c
parentd58ccfeeaaa170c391f2ad83d72d01a059e68955 (diff)
numeric.c: reduced repeated calls
* numeric.c (rb_num2ll, rb_num2ull, fix_pow): turn repeated RFLOAT_VALUE calls into local variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/numeric.c b/numeric.c
index 597bfb5..f79e78f 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3065,9 +3065,9 @@ rb_num2ll(VALUE val)
if (FIXNUM_P(val)) return (LONG_LONG)FIX2LONG(val);
else if (RB_TYPE_P(val, T_FLOAT)) {
- if (RFLOAT_VALUE(val) < LLONG_MAX_PLUS_ONE
- && (LLONG_MIN_MINUS_ONE_IS_LESS_THAN(RFLOAT_VALUE(val)))) {
- return (LONG_LONG)(RFLOAT_VALUE(val));
+ double d = RFLOAT_VALUE(val);
+ if (d < LLONG_MAX_PLUS_ONE && (LLONG_MIN_MINUS_ONE_IS_LESS_THAN(d))) {
+ return (LONG_LONG)d;
}
else {
FLOAT_OUT_OF_RANGE(val, "long long");
@@ -3097,11 +3097,11 @@ rb_num2ull(VALUE val)
return (LONG_LONG)FIX2LONG(val); /* this is FIX2LONG, intended */
}
else if (RB_TYPE_P(val, T_FLOAT)) {
- if (RFLOAT_VALUE(val) < ULLONG_MAX_PLUS_ONE
- && LLONG_MIN_MINUS_ONE_IS_LESS_THAN(RFLOAT_VALUE(val))) {
- if (0 <= RFLOAT_VALUE(val))
- return (unsigned LONG_LONG)(RFLOAT_VALUE(val));
- return (unsigned LONG_LONG)(LONG_LONG)(RFLOAT_VALUE(val));
+ double d = RFLOAT_VALUE(val);
+ if (d < ULLONG_MAX_PLUS_ONE && LLONG_MIN_MINUS_ONE_IS_LESS_THAN(d)) {
+ if (0 <= d)
+ return (unsigned LONG_LONG)d;
+ return (unsigned LONG_LONG)(LONG_LONG)d;
}
else {
FLOAT_OUT_OF_RANGE(val, "unsigned long long");
@@ -3983,13 +3983,13 @@ fix_pow(VALUE x, VALUE y)
return rb_big_pow(x, y);
}
else if (RB_TYPE_P(y, T_FLOAT)) {
- if (RFLOAT_VALUE(y) == 0.0) return DBL2NUM(1.0);
+ double dy = RFLOAT_VALUE(y);
+ if (dy == 0.0) return DBL2NUM(1.0);
if (a == 0) {
- return DBL2NUM(RFLOAT_VALUE(y) < 0 ? INFINITY : 0.0);
+ return DBL2NUM(dy < 0 ? INFINITY : 0.0);
}
if (a == 1) return DBL2NUM(1.0);
{
- double dy = RFLOAT_VALUE(y);
if (a < 0 && dy != round(dy))
return num_funcall1(rb_complex_raw1(x), idPow, y);
return DBL2NUM(pow((double)a, dy));