summaryrefslogtreecommitdiff
path: root/ext/bigdecimal/lib
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-03 07:47:00 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-03 07:47:00 +0000
commit1c3e07f0d6d237222192f41c84716c15731b3158 (patch)
treeb207b1f80d418c4b57eec8a213d83e4069d95406 /ext/bigdecimal/lib
parent59cad45f9963b359b16c1b9a9324b78e5e0873d5 (diff)
* ext/bigdecimal/bigdecimal.c (Init_bigdecimal): add two new constants BigDecimal::INFINITY and BigDecimal::NAN.
* ext/bigdecimal/lib/bigdecimal/math.rb (BigMath.exp): modify the behaviors for infinity arguments as same as Math.exp. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28533 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
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