summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-10-26 08:01:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-10-26 08:01:41 +0000
commit92d83c93546547a5d43cdf3afdc4ec09ef086475 (patch)
tree8160229d89bd0521fdd4aa16ea64479c9c46e184 /numeric.c
parent8f009c18e81e75e0632da6042c33cba7a40bd252 (diff)
* numeric.c (fix_pow): returns infinity for 0**-1. [ruby-dev:32084]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@13785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/numeric.c b/numeric.c
index 07eca3e04e..fca31531bd 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2243,6 +2243,7 @@ static VALUE
fix_pow(x, y)
VALUE x, y;
{
+ static const double zero = 0.0;
long a = FIX2LONG(x);
if (FIXNUM_P(y)) {
@@ -2252,7 +2253,10 @@ fix_pow(x, y)
if (b == 0) return INT2FIX(1);
if (b == 1) return x;
a = FIX2LONG(x);
- if (a == 0) return INT2FIX(0);
+ if (a == 0) {
+ if (b > 0) return INT2FIX(0);
+ return rb_float_new(1.0 / zero);
+ }
if (a == 1) return INT2FIX(1);
if (a == -1) {
if (b % 2 == 0)
@@ -2276,7 +2280,9 @@ fix_pow(x, y)
x = rb_int2big(FIX2LONG(x));
return rb_big_pow(x, y);
case T_FLOAT:
- if (a == 0) return rb_float_new(0.0);
+ if (a == 0) {
+ return rb_float_new(RFLOAT(y)->value < 0 ? (1.0 / zero) : 0.0);
+ }
if (a == 1) return rb_float_new(1.0);
return rb_float_new(pow((double)a, RFLOAT(y)->value));
default: