summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c8
-rw-r--r--ext/bigdecimal/lib/bigdecimal/math.rb10
2 files changed, 17 insertions, 1 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 817fc13cfd5..340ea8bb804 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -1902,6 +1902,8 @@ BigDecimal_sign(VALUE self)
void
Init_bigdecimal(void)
{
+ VALUE arg;
+
/* Initialize VP routines */
VpInit((U_LONG)0);
@@ -2023,6 +2025,12 @@ Init_bigdecimal(void)
/* -3: Indicates that a value is negative and infinite. See BigDecimal.sign. */
rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_INFINITE",INT2FIX(VP_SIGN_NEGATIVE_INFINITE));
+ arg = rb_str_new2("+Infinity");
+ rb_define_const(rb_cBigDecimal, "INFINITY", BigDecimal_global_new(1, &arg, rb_cBigDecimal));
+ arg = rb_str_new2("NaN");
+ rb_define_const(rb_cBigDecimal, "NAN", BigDecimal_global_new(1, &arg, rb_cBigDecimal));
+
+
/* instance methods */
rb_define_method(rb_cBigDecimal, "precs", BigDecimal_prec, 0);
diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb
index 41fc69f66c5..c17841fdb96 100644
--- a/ext/bigdecimal/lib/bigdecimal/math.rb
+++ b/ext/bigdecimal/lib/bigdecimal/math.rb
@@ -155,7 +155,15 @@ module BigMath
# -> "0.271828182845904523536028752390026306410273E1"
def exp(x, prec)
raise ArgumentError, "Zero or negative precision for exp" if prec <= 0
- return BigDecimal("NaN") if x.infinite? || x.nan?
+ if x.infinite?
+ if x < 0
+ return BigDecimal("0", prec)
+ else
+ return BigDecimal("+Infinity", prec)
+ end
+ elsif x.nan?
+ return BigDecimal("NaN", prec)
+ end
n = prec + BigDecimal.double_fig
one = BigDecimal("1")
x = -x if neg = x < 0