The tanh() is an inbuilt function in Ruby returns the hyperbolic tangent of value given in radians. The value passed is in range [-inf, +inf]. The returned value is in range [-1, +1].
Syntax: Math.tanh(value) Parameters: The function accepts one mandatory parameter value whose corresponding hyperbolic tangent value is returned. Return Value: It returns the hyperbolic tangent value.
Example 1:
#Ruby program for tanh() function
#Assigning values
val1 = -1023 val2 = 0.67 val3 = 98 val4 = -39
#Prints the tanh() value
puts Math.tanh(val1)
puts Math.tanh(val2)
puts Math.tanh(val3)
puts Math.tanh(val4)
Output:
-1.0 0.5849798828807289 1.0 -1.0
Example 2:
#Ruby program for tanh() function
#Assigning values
val1 = 0 val2 = 100 val3 = -98 val4 = -6
#Prints the tanh() value
puts Math.tanh(val1)
puts Math.tanh(val2)
puts Math.tanh(val3)
puts Math.tanh(val4)
Output:
0.0 1.0 -1.0 -0.9999877116507956