Swift Tutorial Swift References

Swift - atan() Function



The Swift atan() function returns arc tangent of a value. The returned value will be in the range -𝜋/2 through 𝜋/2.

Syntax

In Foundation framework, it is defined as follows:

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

Parameters

x Specify the value.

Return Value

Returns the arc tangent of the value.

Example:

In the example below, atan() function is used to is used to find out the arc tangent of a given value.

import Foundation

print("atan(0.0) = \(atan(0.0))")
print("atan(0.5) = \(atan(0.5))")
print("atan(1.0) = \(atan(1.0))")
print("atan(2.0) = \(atan(2.0))")

The output of the above code will be:

atan(0.0) = 0.0
atan(0.5) = 0.4636476090008061
atan(1.0) = 0.7853981633974483
atan(2.0) = 1.1071487177940904

❮ Swift Math Functions