Ruby CMath tanh() 方法与示例
tanh() 方法是 Math 类,用于返回给定值的双曲正切值。
Syntax: Math.tanh(z)
Parameter: Here, z is the value whose hyberbolic tangent is to be calculated.
Returns: This method returns the hyberbolic tangent value of the z.
示例 #1:
# Ruby code for tanh() method
require 'cmath'
# Initializing variable
a = 0.3584
b = 2
puts "tanh value of a : #{CMath.tanh(a)}\n\n"
puts "tanh value of b : #{CMath.tanh(b)}\n\n"
输出:
//Write Java code here
tanh value of a : 0.3438039328469827
tanh value of b : 0.9640275800758169
示例 #2:
# Ruby code for tanh() method
require 'cmath'
# Initializing variable
a = 0
b = -0.247
puts "tanh value of a : #{CMath.tanh(a)}\n\n"
puts "tanh value of b : #{CMath.tanh(b)}\n\n"
输出:
tanh value of a : 0.0
tanh value of b : -0.24209655276165779