Ruby | Math tanh() function

The tanh() is an inbuilt function in Ruby returns the 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

#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)

chevron_right


Output:

-1.0
0.5849798828807289
1.0
-1.0

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#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)

chevron_right


Output:

0.0
1.0
-1.0
-0.9999877116507956

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.