Ruby Tutorial Ruby References

Ruby - Math.tanh() Method



The Ruby Math.tanh() method returns hyperbolic tangent of a value. The hyperbolic tangent of x is defined as:

tanh

where e is an Euler's number.

Syntax

Math.tanh(x)

Parameters

x Specify the value.

Return Value

Returns the hyperbolic tangent of a value.

Example:

In the example below, Math.tanh() method is used to find out the hyperbolic tangent of a value.

puts "Math.tanh(-4) = #{Math.tanh(-4)}"
puts "Math.tanh(-2) = #{Math.tanh(-2)}"
puts "Math.tanh(0) = #{Math.tanh(0)}"
puts "Math.tanh(2) = #{Math.tanh(2)}"
puts "Math.tanh(4) = #{Math.tanh(4)}"

The output of the above code will be:

Math.tanh(-4) = -0.999329299739067
Math.tanh(-2) = -0.9640275800758169
Math.tanh(0) = 0.0
Math.tanh(2) = 0.9640275800758169
Math.tanh(4) = 0.999329299739067

❮ Ruby Math Module