Math
public protocol Math : SignedNumeric
A signed numeric type that supports elementary functions.
The Math protocol provides a suitable basis for writing functions that
work on any real or complex floating-point type that supports the required
functions.
Topics
- pi
- e
- phi
- /(_:_:)
- /=(_:_:)
- **(_:_:)
- **=(_:_:)
- naturalExponential()
- binaryExponential()
- commonExponential()
- naturalExponentialMinusOne()
- naturalLogarithm()
- binaryLogarithm()
- commonLogarithm()
- naturalLogarithmOnePlus()
- squareRoot()
- cubeRoot()
- sine()
- cosine()
- tangent()
- inverseSine()
- inverseCosine()
- inverseTangent()
- hyperbolicSine()
- hyperbolicCosine()
- hyperbolicTangent()
- inverseHyperbolicSine()
- inverseHyperbolicCosine()
- inverseHyperbolicTangent()
-
The mathematical constant pi (π).
This value should be rounded toward zero to keep user computations with angles from inadvertently ending up in the wrong quadrant. A type that conforms to the
Mathprotocol provides the value forpiat its best possible precision.Declaration
Swift
static var pi: Self -
The mathematical constant e, or Euler’s number.
Declaration
Swift
static var e: Self -
The mathematical constant phi (φ), or golden ratio.
Declaration
Swift
static var phi: Self -
Returns the quotient obtained by dividing the first value by the second, rounded to a representable value.
Declaration
Swift
static func / (lhs: Self, rhs: Self) -> SelfParameters
lhs-
The value to divide.
rhs-
The value by which to divide
lhs.
-
Divides the left-hand side by the right-hand side and stores the quotient in the left-hand side, rounded to a representable value.
Declaration
Swift
static func /= (lhs: inout Self, rhs: Self)Parameters
lhs-
The value to divide.
rhs-
The value by which to divide
lhs.
-
Returns the result of raising the first value to the power of the second, rounded to a representable value.
Declaration
Swift
static func ** (lhs: Self, rhs: Self) -> SelfParameters
lhs-
The value to be raised to the power of
rhs. rhs-
The value by which to raise
lhs.
-
Raises the left-hand side to the power of the right-hand side and stores the result in the left-hand side, rounded to a representable value.
Declaration
Swift
static func **= (lhs: inout Self, rhs: Self)Parameters
lhs-
The value to be raised to the power of
rhs. rhs-
The value by which to raise
lhs.
-
Returns the natural exponential of the value, rounded to a representable value.
The natural exponential of a value
xis e (2.7182818…) raised to the power ofx.See also
exp(_:)Declaration
Swift
func naturalExponential() -> Self -
Returns the binary exponential of the value, rounded to a representable value.
The binary exponential of a value
xis 2 raised to the power ofx.See also
exp2(_:)Declaration
Swift
func binaryExponential() -> Self -
Returns the common exponential of the value, rounded to a representable value.
The common exponential of a value
xis 10 raised to the power ofx.See also
exp10(_:)Declaration
Swift
func commonExponential() -> Self -
Returns the result of subtracting one from the natural exponential of the value, rounded to a representable value.
The natural exponential of a value
xis e (2.7182818…) raised to the power ofx.This function is more accurate than
x.naturalExponential() - 1for values ofxclose to zero.See also
expm1(_:)Declaration
Swift
func naturalExponentialMinusOne() -> Self -
Returns the natural (base e) logarithm of the value, rounded to a representable value.
See also
log(_:)Declaration
Swift
func naturalLogarithm() -> Self -
Returns the binary (base 2) logarithm of the value, rounded to a representable value.
See also
log2(_:)Declaration
Swift
func binaryLogarithm() -> Self -
Returns the common (base 10) logarithm of the value, rounded to a representable value.
See also
log10(_:)Declaration
Swift
func commonLogarithm() -> Self -
Returns the natural (base e) logarithm of the result of adding one to the value, rounded to a representable value.
See also
log1p(_:)Declaration
Swift
func naturalLogarithmOnePlus() -> Self -
Returns the square root of the value, rounded to a representable value.
See also
sqrt(_:)Declaration
Swift
func squareRoot() -> Self -
Returns the cube root of the value, rounded to a representable value.
See also
cbrt(_:)Declaration
Swift
func cubeRoot() -> Self -
Returns the sine of the value (given in radians), rounded to a representable value.
See also
sin(_:)Declaration
Swift
func sine() -> Self -
Returns the cosine of the value (given in radians), rounded to a representable value.
See also
cos(_:)Declaration
Swift
func cosine() -> Self -
Returns the tangent of the value (given in radians), rounded to a representable value.
See also
tan(_:)Declaration
Swift
func tangent() -> Self -
Returns the principal value of the inverse sine of the value, rounded to a representable value.
See also
asin(_:)Declaration
Swift
func inverseSine() -> Self -
Returns the principal value of the inverse cosine of the value, rounded to a representable value.
See also
acos(_:)Declaration
Swift
func inverseCosine() -> Self -
Returns the principal value of the inverse tangent of the value, rounded to a representable value.
See also
atan(_:)Declaration
Swift
func inverseTangent() -> Self -
Returns the hyperbolic sine of the value, rounded to a representable value.
See also
sinh(_:)Declaration
Swift
func hyperbolicSine() -> Self -
Returns the hyperbolic cosine of the value, rounded to a representable value.
See also
cosh(_:)Declaration
Swift
func hyperbolicCosine() -> Self -
Returns the hyperbolic tangent of the value, rounded to a representable value.
See also
tanh(_:)Declaration
Swift
func hyperbolicTangent() -> Self -
Returns the principal value of the inverse hyperbolic sine of the value, rounded to a representable value.
See also
asinh(_:)Declaration
Swift
func inverseHyperbolicSine() -> Self -
Returns the principal value of the inverse hyperbolic cosine of the value, rounded to a representable value.
See also
acosh(_:)Declaration
Swift
func inverseHyperbolicCosine() -> Self -
Returns the principal value of the inverse hyperbolic tangent of the value, rounded to a representable value.
See also
atanh(_:)Declaration
Swift
func inverseHyperbolicTangent() -> Self
-
Returns the result of raising
baseto the power ofexponent, rounded to a representable value (deprecated).Declaration
Swift
public static func pow(_ base: Self, _ exponent: Self) -> SelfParameters
base-
The base to be raised to the power of
exponent. exponent-
The exponent by which to raise
base.
-
Returns the natural exponential of
x, rounded to a representable value.The natural exponential of a value
xis e (2.7182818…) raised to the power ofx.See also
naturalExponential()Declaration
Swift
public static func exp(_ x: Self) -> Self -
Returns the binary exponential of
x, rounded to a representable value.The binary exponential of a value
xis 2 raised to the power ofx.See also
binaryExponential()Declaration
Swift
public static func exp2(_ x: Self) -> Self -
Returns the common exponential of
x, rounded to a representable value.The common exponential of a value
xis 10 raised to the power ofx.See also
commonExponential()Declaration
Swift
public static func exp10(_ x: Self) -> Self -
Returns the result of subtracting one from the natural exponential of
x, rounded to a representable value.The natural exponential of a value
xis e (2.7182818…) raised to the power ofx.This function is more accurate than
.exp(x) - 1for values ofxclose to zero.See also
naturalExponentialMinusOne()Declaration
Swift
public static func expm1(_ x: Self) -> Self -
Returns the natural (base e) logarithm of
x, rounded to a representable value.See also
naturalLogarithm()Declaration
Swift
public static func log(_ x: Self) -> Self -
Returns the binary (base 2) logarithm of
x, rounded to a representable value.See also
binaryLogarithm()Declaration
Swift
public static func log2(_ x: Self) -> Self -
Returns the common (base 10) logarithm of
x, rounded to a representable value.See also
commonLogarithm()Declaration
Swift
public static func log10(_ x: Self) -> Self -
Returns the natural (base e) logarithm of the result of adding one to
x, rounded to a representable value.See also
naturalLogarithmOnePlus()Declaration
Swift
public static func log1p(_ x: Self) -> Self -
Returns the square root of
x, rounded to a representable value.See also
squareRoot()Declaration
Swift
public static func sqrt(_ x: Self) -> Self -
Returns the cube root of
x, rounded to a representable value.See also
cubeRoot()Declaration
Swift
public static func cbrt(_ x: Self) -> Self -
Returns the sine of
x(given in radians), rounded to a representable value.See also
sine()Declaration
Swift
public static func sin(_ x: Self) -> Self -
Returns the cosine of
x(given in radians), rounded to a representable value.See also
cosine()Declaration
Swift
public static func cos(_ x: Self) -> Self -
Returns the tangent of
x(given in radians), rounded to a representable value.See also
tangent()Declaration
Swift
public static func tan(_ x: Self) -> Self -
Returns the principal value of the inverse sine of
x, rounded to a representable value.See also
inverseSine()Declaration
Swift
public static func asin(_ x: Self) -> Self -
Returns the principal value of the inverse cosine of
x, rounded to a representable value.See also
inverseCosine()Declaration
Swift
public static func acos(_ x: Self) -> Self -
Returns the principal value of the inverse tangent of
x, rounded to a representable value.See also
inverseTangent()Declaration
Swift
public static func atan(_ x: Self) -> Self -
Returns the hyperbolic sine of
x, rounded to a representable value.See also
hyperbolicSine()Declaration
Swift
public static func sinh(_ x: Self) -> Self -
Returns the hyperbolic cosine of
x, rounded to a representable value.See also
hyperbolicCosine()Declaration
Swift
public static func cosh(_ x: Self) -> Self -
Returns the hyperbolic tangent of
x, rounded to a representable value.See also
hyperbolicTangent()Declaration
Swift
public static func tanh(_ x: Self) -> Self -
Returns the principal value of the inverse hyperbolic sine of
x, rounded to a representable value.See also
inverseHyperbolicSine()Declaration
Swift
public static func asinh(_ x: Self) -> Self -
Returns the principal value of the inverse hyperbolic cosine of
x, rounded to a representable value.See also
inverseHyperbolicCosine()Declaration
Swift
public static func acosh(_ x: Self) -> Self -
Returns the principal value of the inverse hyperbolic tangent of
x, rounded to a representable value.See also
inverseHyperbolicTangent()Declaration
Swift
public static func atanh(_ x: Self) -> Self