Swift - asin() Function
The Swift asin() function returns arc sine 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 asin(_ x: CGFloat) -> CGFloat public func asin(_ x: Float) -> Float public func asin(_ x: Float80) -> Float80 public func asin(_ __x: Double) -> Double
Parameters
x |
Specify the value in range [-1.0, 1.0]. |
Return Value
Returns the arc sine of the value.
If the x is not in the range of [-1.0, 1.0], it returns nan.
Example:
In the example below, asin() function is used to is used to find out the arc sine of a given value.
import Foundation print("asin(0.0) = \(asin(0.0))") print("asin(0.5) = \(asin(0.5))") print("asin(1.0) = \(asin(1.0))") print("asin(2.0) = \(asin(2.0))")
The output of the above code will be:
asin(0.0) = 0.0 asin(0.5) = 0.5235987755982989 asin(1.0) = 1.5707963267948966 asin(2.0) = nan
❮ Swift Math Functions