红宝石 | BigDecimal exp()函数
BigDecimal#exp() : exp()是一个 BigDecimal 类方法,它返回 e 的值(自然对数的底)的小数次方,精确到指定的位数。
Syntax: BigDecimal.exp()
Parameter: BigDecimal values
Return: the value of e (the base of natural logarithms) raised to the power of decimal
示例 #1:
# Ruby code for BigDecimal.exp() method
# loading library
require 'bigdecimal'
# declaring bigdecimal
a = BigDecimal("10")
# declaring bigdecimal
b = BigDecimal("1000") *2
# declaring bigdecimal
c = BigDecimal("11.43")
# exp() method
puts "BigDecimal a exp method : #{Math.exp(a)}\n\n"
puts "BigDecimal b exp method : #{Math.exp(b)}\n\n"
puts "BigDecimal a exp method : #{Math.exp(c)}\n\n"
输出 :
BigDecimal a exp method : 22026.465794806718
BigDecimal b exp method : Infinity
BigDecimal a exp method : 92041.97481768382
示例 #2:
# Ruby code for BigDecimal.exp() method
# loading library
require 'bigdecimal'
# declaring bigdecimal
a = BigDecimal('12')*12
# declaring bigdecimal
b = BigDecimal('10')+(22 ** 7.1) ** 10
# declaring bigdecimal
c = -BigDecimal('-3')
# exp() method
puts "BigDecimal a exp method : #{Math.exp(a)}\n\n"
puts "BigDecimal b exp method : #{Math.exp(b)}\n\n"
puts "BigDecimal a exp method : #{Math.exp(c)}\n\n"
输出 :
BigDecimal a exp method : 3.454660656717546e+62
BigDecimal b exp method : Infinity
BigDecimal a exp method : 20.085536923187668