Ruby Tutorial Ruby References

Ruby - Math.cosh() Method



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

cosh

where e is an Euler's number.

Syntax

Math.cosh(x)

Parameters

x Specify the value.

Return Value

Returns the hyperbolic cosine of a value.

Example:

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

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

The output of the above code will be:

Math.cosh(-4) = 27.308232836016487
Math.cosh(-2) = 3.7621956910836314
Math.cosh(0) = 1.0
Math.cosh(2) = 3.7621956910836314
Math.cosh(4) = 27.308232836016487

❮ Ruby Math Module