Skip to content

Commit

Permalink
* numeric.c (fix_pow): returns infinity for 0**-1. [ruby-dev:32084]
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Oct 26, 2007
1 parent 32865ef commit 31667e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Fri Oct 26 17:01:34 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>

* numeric.c (fix_pow): returns infinity for 0**-1. [ruby-dev:32084]

Fri Oct 26 15:00:52 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>

* misc/ruby-style.el (ruby-style-{case,label}-indent): adjust for
Expand Down
10 changes: 8 additions & 2 deletions numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -2326,14 +2326,18 @@ 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)) {
long b = FIX2LONG(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)
Expand All @@ -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:
Expand Down

0 comments on commit 31667e5

Please sign in to comment.