Functions
The following functions are available globally.
-
Computes the absolute value of a number.
Declaration
func abs(_ x: Double) -> Double
Parameters
xA number value.
Return Value
The absolute value of
x
. -
Computes the arc tangent of two numbers.
The atan2() function is used to convert from rectangular (x,y) to polar (r,theta) coordinates where
theta = atan2(y, x)
.Declaration
func atan2(_ y: Double, _ x: Double) -> Double
Parameters
yA number value.
xA number value.
Return Value
The arc tangent of
y/x
, taking into account the signs of both arguments to determine the quadrant. -
Computes the ceiling (rounding up) of a number.
Declaration
func ceil(_ x: Double) -> Double
Parameters
xA number value.
Return Value
The smallest integer greater than or equal to
x
. -
Computes the cosine of a number.
Declaration
func cos(_ x: Double) -> Double
Parameters
xA number value.
Return Value
The cosine of
x
. -
Computes the base-e exponential of a number.
Declaration
func exp(_ x: Double) -> Double
Parameters
xA number value.
Return Value
Euler’s number e to raised to the power of
x
. -
Computes the floor (rounding down) of a number.
Declaration
func floor(_ x: Double) -> Double
Parameters
xA number value.
Return Value
The largest integer less than or equal to
x
. -
Computes the natural logarithm of a number.
Declaration
func log(_ x: Double) -> Double
Parameters
xA number value.
Return Value
The natural logarithm of
x
. -
Computes the power function.
Declaration
func pow(_ x: Double, _ y: Double) -> Double
Parameters
xA number value used as the base.
yA number value used as the exponent.
Return Value
x
raised to the power ofy
. -
Rounds a number to the closest integer.
Declaration
func round(_ x: Double) -> Double
Parameters
xA number value.
Return Value
The integer closest to
x
, half-way cases round away from zero. -
Computes the sine of a number.
Declaration
func sin(_ x: Double) -> Double
Parameters
xA number value.
Return Value
The sine of
x
. -
Computes the square root of a number.
Declaration
func sqrt(_ x: Double) -> Double
Parameters
xA number value.
Return Value
The square root of
x
. -
Computes the tangent of a number.
Declaration
func tan(_ x: Double) -> Double
Parameters
xA number value.
Return Value
The tangent of
x
.