diff options
| author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-05 07:38:41 +0000 |
|---|---|---|
| committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-07-05 07:38:41 +0000 |
| commit | 8a30534f3082dd7a9903172be20cd33b435753d4 (patch) | |
| tree | 8861b51f7fd9fa15bc9d86a5c808a0e417efe161 /numeric.c | |
| parent | e428bdb8546937c2bcb90ba413290e0335a45610 (diff) | |
| download | ruby-8a30534f3082dd7a9903172be20cd33b435753d4.tar.gz ruby-8a30534f3082dd7a9903172be20cd33b435753d4.tar.xz ruby-8a30534f3082dd7a9903172be20cd33b435753d4.zip | |
* numeric.c (int_pow): fix previous nubu's commit.
* test/ruby/test_fixnum.rb: new test.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@12698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
| -rw-r--r-- | numeric.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -2281,7 +2281,10 @@ int_pow(long x, unsigned long y) long z = 1; if (neg) x = -x; - if (y & 1) z = x; + if (y & 1) + z = x; + else + neg = 0; y &= ~1; do { while (y % 2 == 0) { @@ -2289,8 +2292,8 @@ int_pow(long x, unsigned long y) if (x2 < x || !POSFIXABLE(x2)) { VALUE v; bignum: - v = rb_big_pow(rb_int2big(neg ? -x : x), LONG2NUM(y)); - if (z != 1) v = rb_big_mul(rb_int2big(z), v); + v = rb_big_pow(rb_int2big(x), LONG2NUM(y)); + if (z != 1) v = rb_big_mul(rb_int2big(neg ? -z : z), v); return v; } x = x2; @@ -2304,7 +2307,7 @@ int_pow(long x, unsigned long y) z = xz; } } while (--y); - if (neg && (y & 1)) z = -z; + if (neg) z = -z; return LONG2NUM(z); } |
