红宝石 |数学 log10()函数
Ruby 中的log10()函数返回X的以 10 为底的对数值。
Syntax: Math.log10(X)
Parameter: The function takes one mandatory parameter X whose base 10 logarithm value is to be returned.
Return Value: The function the base 10 logarithm value of X.
示例 1 :
# Ruby program for log10() function
# Assigning values
val1 = 213
val2 = 256
val3 = 27
val4 = 100
# Prints the value returned by log10()
puts Math.log10(val1)
puts Math.log10(val2)
puts Math.log10(val3)
puts Math.log10(val4)
输出:
2.3283796034387376
2.4082399653118496
1.4313637641589874
2.0
示例 2 :
# Ruby program for log10() function
# Assigning values
val1 = 21
val2 = 2
val3 = 19
val4 = 121
# Prints the value returned by log10()
puts Math.log10(val1)
puts Math.log10(val2)
puts Math.log10(val3)
puts Math.log10(val4)
输出:
1.3222192947339193
0.3010299956639812
1.2787536009528289
2.08278537031645
参考:https://devdocs.io/ruby~2.5/math#method-c-log10