Open In App

Ruby | Math tanh() function

Last Updated : 20 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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

CPP




#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

CPP




#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

Reference: https://devdocs.io/ruby~2.5/math#method-c-tanh



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads