Swift Tutorial Swift References

Swift - acosh() Function



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

acosh

Syntax

In Foundation framework, it is defined as follows:

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

Parameters

x Specify the value equal to or greater than 1.0.

Return Value

Returns the inverse hyperbolic cosine of a value.
If the x is less than 1.0, it returns -nan.

Example:

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

import Foundation

print("acosh(0.0) = \(acosh(0.0))")
print("acosh(2.0) = \(acosh(2.0))")
print("acosh(4.0) = \(acosh(4.0))")
print("acosh(8.0) = \(acosh(8.0))")

The output of the above code will be:

acosh(0.0) = -nan
acosh(2.0) = 1.3169578969248166
acosh(4.0) = 2.0634370688955608
acosh(8.0) = 2.7686593833135738

❮ Swift Math Functions