summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bigdecimal/lib')
-rw-r--r--ext/bigdecimal/lib/bigdecimal/math.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb
index 41fc69f..c17841f 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