summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-07 18:05:03 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-07 18:05:03 +0000
commit24a9bf988c896f073d0d483a117c4197f93006c2 (patch)
treeda8705223870f368ade237a07eeedf57d1da63e5 /numeric.c
parentb940547cb9c9a5d29f72ad2683e8868bc389c5e1 (diff)
merge revision(s) 13785:
* 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_6@16919 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 51a1fb2337..6d69df943e 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2202,6 +2202,7 @@ static VALUE
fix_pow(x, y)
VALUE x, y;
{
+ static const double zero = 0.0;
long a = FIX2LONG(x);
if (FIXNUM_P(y)) {
@@ -2211,7 +2212,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)
@@ -2235,7 +2239,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: