Swift - sin() Function
The Swift sin() function returns trigonometric sine of an angle (angle should be in radians). The returned value will be in the range -1 through 1.
In the graph below, sin(x) vs x is plotted.
Syntax
In Foundation framework, it is defined as follows:
public func sin(_ x: CGFloat) -> CGFloat public func sin(_ x: Float) -> Float public func sin(_ x: Float80) -> Float80 public func sin(_ __x: Double) -> Double
Parameters
x |
Specify the angle in radian. |
Return Value
Returns the trigonometric sine of an angle.
Example:
In the example below, sin() function is used to find out the trigonometric sine of an angle.
import Foundation var pi = Double.pi print("sin(pi/6) = \(sin(pi/6))") print("sin(pi/4) = \(sin(pi/4))") print("sin(pi/3) = \(sin(pi/3))")
The output of the above code will be:
sin(pi/6) = 0.49999999999999994 sin(pi/4) = 0.7071067811865475 sin(pi/3) = 0.8660254037844386
❮ Swift Math Functions