aboutsummaryrefslogtreecommitdiffstats
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
commit31667e5ffc1f99f745664ff7a80791ebb5875841 (patch)
treed04ffaa036ef5ca06abd1f321e19524bacf9e011 /numeric.c
parent32865ef821a045b1bf14c4cfcfc52c70125b3794 (diff)
downloadruby-31667e5ffc1f99f745664ff7a80791ebb5875841.tar.gz
* numeric.c (fix_pow): returns infinity for 0**-1. [ruby-dev:32084]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@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 1ecac751bf..3c0cfdaaa6 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2326,6 +2326,7 @@ int_pow(long x, unsigned long y)
static VALUE
fix_pow(VALUE x, VALUE y)
{
+ static const double zero = 0.0;
long a = FIX2LONG(x);
if (FIXNUM_P(y)) {
@@ -2333,7 +2334,10 @@ fix_pow(VALUE x, VALUE y)
if (b == 0) return INT2FIX(1);
if (b == 1) return 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)
@@ -2357,7 +2361,9 @@ fix_pow(VALUE x, VALUE 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: