Open In App

Ruby CMath tanh() Method with example

Last Updated : 12 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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

Syntax: Math.tanh(z) Parameter: Here, z is the value whose hyperbolic tangent is to be calculated. Returns: This method returns the hyperbolic tangent value of the z.

Example #1: 

Ruby




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


Output: 

tanh value of a : 0.3438039328469827

tanh value of b : 0.9640275800758169

Time Complexity : O(1)

Auxiliary Space: O(1)

Example #2: 

Ruby




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


Output:

tanh value of a : 0.0

tanh value of b : -0.24209655276165779

 Time Complexity : O(1)

 Auxiliary Space: O(1)


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads