Ruby CMath tanh() Method with example

tanh() method is Math class which is used to returns the hyberbolic tangent of the given value.

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.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

filter_none

edit
close

play_arrow

link
brightness_4
code

//Write Java code here

chevron_right


tanh value of a : 0.3438039328469827

tanh value of b : 0.9640275800758169

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

tanh value of a : 0.0

tanh value of b : -0.24209655276165779


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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.