Swift Tutorial Swift References

Swift - atanh() Function



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

atanh

Syntax

In Foundation framework, it is defined as follows:

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

Parameters

x Specify the value in range [-1.0, 1.0].

Return Value

Returns the inverse hyperbolic tangent of a value.
If the x is not in the range of [-1.0, 1.0], it returns -nan.
If the x is -1.0, it returns -inf.
If the x is 1.0, it returns inf.

Example:

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

import Foundation

print("atanh(-1.0) = \(atanh(-1.0))")
print("atanh(-0.5) = \(atanh(-0.5))")
print("atanh(0.0) = \(atanh(0.0))")
print("atanh(0.5) = \(atanh(0.5))")
print("atanh(1.0) = \(atanh(1.0))")
print("atanh(2.0) = \(atanh(2.0))")

The output of the above code will be:

atanh(-1.0) = -inf
atanh(-0.5) = -0.5493061443340548
atanh(0.0) = 0.0
atanh(0.5) = 0.5493061443340548
atanh(1.0) = inf
atanh(2.0) = -nan

❮ Swift Math Functions