diff options
Diffstat (limited to 'numeric.c')
-rw-r--r-- | numeric.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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: |