aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-05 07:27:19 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-05 07:27:19 +0000
commit194ff269493be5df0248ebf4cb50412ed8a01c3a (patch)
tree423a6871548455e5cb0fb400e7167b4065b55089 /numeric.c
parentf2f94c95a24b88cba856258e21dd1ab6fd57fc07 (diff)
downloadruby-194ff269493be5df0248ebf4cb50412ed8a01c3a.tar.gz
numeric.c: short circuit
* numeric.c (int_pow): short circuit when y is 0, always return 1. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/numeric.c b/numeric.c
index 28ad30d764..ee8c032eef 100644
--- a/numeric.c
+++ b/numeric.c
@@ -3892,6 +3892,7 @@ int_pow(long x, unsigned long y)
int neg = x < 0;
long z = 1;
+ if (y == 0) return INT2FIX(1);
if (neg) x = -x;
if (y & 1)
z = x;