Swift Tutorial Swift References

Swift - cosh() Function



The Swift cosh() function returns hyperbolic cosine of a value. The hyperbolic cosine of x is defined as:

cosh

where e is an Euler's number.

Syntax

In Foundation framework, it is defined as follows:

public func cosh(_ x: CGFloat) -> CGFloat
public func cosh(_ x: Float) -> Float
public func cosh(_ x: Float80) -> Float80
public func cosh(_ __x: Double) -> Double

Parameters

x Specify the value.

Return Value

Returns the hyperbolic cosine of a value.

Example:

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

import Foundation

print("cosh(-4.0) = \(cosh(-4.0))")
print("cosh(-2.0) = \(cosh(-2.0))")
print("cosh(0.0) = \(cosh(0.0))")
print("cosh(2.0) = \(cosh(2.0))")
print("cosh(4.0) = \(cosh(4.0))")

The output of the above code will be:

cosh(-4.0) = 27.308232836016487
cosh(-2.0) = 3.7621956910836314
cosh(0.0) = 1.0
cosh(2.0) = 3.7621956910836314
cosh(4.0) = 27.308232836016487

❮ Swift Math Functions