红宝石 |数学 exp()函数
Ruby 中的exp()函数返回 e^value 的值。它在[-inf, +inf]范围内取值,并在[0, infinity]范围内返回答案。
Syntax: Math.exp(value)
Parameter: The function takes the value which is to be raised to the power of e.
Return Value: The function returns the value of e^value.
示例 1 :
# Ruby program for exp() function
# Assigning values
val1 = 0.98
val2 = -0.9
val3 = 6
val4 = 1
# Prints the exp() value
puts Math.exp(val1)
puts Math.exp(val2)
puts Math.exp(val3)
puts Math.exp(val4)
输出:
2.664456241929417
0.4065696597405991
403.4287934927351
2.718281828459045
示例 2 :
# Ruby program for exp() function
# Assigning values
val1 = 0.67
val2 = -0.12
val3 = 2.4
val4 = 89
# Prints the exp() value
puts Math.exp(val1)
puts Math.exp(val2)
puts Math.exp(val3)
puts Math.exp(val4)
输出:
1.9542373206359396
0.8869204367171575
11.023176380641601
4.4896128191743455e+38
参考:https://devdocs.io/ruby~2.5/math#method-c-exp