take the arcsine of a number in swift

To take the arcsine of a number in Swift, you can use the asin() method from the Foundation framework's Darwin module. Here's an example:

main.swift
import Foundation

let x = 0.5
let y = asin(x) // returns the arcsine of x in radians

print(y) // prints "0.523598775598299"
126 chars
7 lines

In this example, we import the Foundation framework and use the asin() function from the Darwin module to calculate the arcsine of x and assign it to y. The result is in radians, so we print it to the console.

Note that the argument to asin() must be between -1 and 1, or else the function will return NaN.

gistlibby LogSnag