NumericAnnex Reference (100% documented)

View on GitHub

Install in Dash

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

    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 Math protocol provides the value for pi at its best possible precision.

    Declaration

    Swift

    static var pi: Self
  • e Default implementation

    The mathematical constant e, or Euler’s number.

    Declaration

    Swift

    static var e: Self
  • phi Default implementation

    The mathematical constant phi (φ), or golden ratio.

    Declaration

    Swift

    static var phi: Self
  • /(_:_:) Default implementation

    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) -> Self
    Parameters
    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.

  • **(_:_:) Default implementation

    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) -> Self
    Parameters
    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.

  • naturalExponential()

    Returns the natural exponential of the value, rounded to a representable value.

    The natural exponential of a value x is e (2.7182818…) raised to the power of x.

    See also

    exp(_:)
    Declaration

    Swift

    func naturalExponential() -> Self
  • binaryExponential() Default implementation

    Returns the binary exponential of the value, rounded to a representable value.

    The binary exponential of a value x is 2 raised to the power of x.

    See also

    exp2(_:)
    Declaration

    Swift

    func binaryExponential() -> Self
  • commonExponential() Default implementation

    Returns the common exponential of the value, rounded to a representable value.

    The common exponential of a value x is 10 raised to the power of x.

    See also

    exp10(_:)
    Declaration

    Swift

    func commonExponential() -> Self
  • naturalExponentialMinusOne() Default implementation

    Returns the result of subtracting one from the natural exponential of the value, rounded to a representable value.

    The natural exponential of a value x is e (2.7182818…) raised to the power of x.

    This function is more accurate than x.naturalExponential() - 1 for values of x close to zero.

    See also

    expm1(_:)
    Declaration

    Swift

    func naturalExponentialMinusOne() -> Self
  • naturalLogarithm()

    Returns the natural (base e) logarithm of the value, rounded to a representable value.

    See also

    log(_:)
    Declaration

    Swift

    func naturalLogarithm() -> Self
  • binaryLogarithm() Default implementation

    Returns the binary (base 2) logarithm of the value, rounded to a representable value.

    See also

    log2(_:)
    Declaration

    Swift

    func binaryLogarithm() -> Self
  • commonLogarithm() Default implementation

    Returns the common (base 10) logarithm of the value, rounded to a representable value.

    See also

    log10(_:)
    Declaration

    Swift

    func commonLogarithm() -> Self
  • naturalLogarithmOnePlus() Default implementation

    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
  • squareRoot()

    Returns the square root of the value, rounded to a representable value.

    See also

    sqrt(_:)
    Declaration

    Swift

    func squareRoot() -> Self
  • cubeRoot()

    Returns the cube root of the value, rounded to a representable value.

    See also

    cbrt(_:)
    Declaration

    Swift

    func cubeRoot() -> Self
  • sine()

    Returns the sine of the value (given in radians), rounded to a representable value.

    See also

    sin(_:)
    Declaration

    Swift

    func sine() -> Self
  • cosine()

    Returns the cosine of the value (given in radians), rounded to a representable value.

    See also

    cos(_:)
    Declaration

    Swift

    func cosine() -> Self
  • tangent() Default implementation

    Returns the tangent of the value (given in radians), rounded to a representable value.

    See also

    tan(_:)
    Declaration

    Swift

    func tangent() -> Self
  • inverseSine()

    Returns the principal value of the inverse sine of the value, rounded to a representable value.

    See also

    asin(_:)
    Declaration

    Swift

    func inverseSine() -> Self
  • inverseCosine()

    Returns the principal value of the inverse cosine of the value, rounded to a representable value.

    See also

    acos(_:)
    Declaration

    Swift

    func inverseCosine() -> Self
  • inverseTangent()

    Returns the principal value of the inverse tangent of the value, rounded to a representable value.

    See also

    atan(_:)
    Declaration

    Swift

    func inverseTangent() -> Self
  • hyperbolicSine()

    Returns the hyperbolic sine of the value, rounded to a representable value.

    See also

    sinh(_:)
    Declaration

    Swift

    func hyperbolicSine() -> Self
  • hyperbolicCosine()

    Returns the hyperbolic cosine of the value, rounded to a representable value.

    See also

    cosh(_:)
    Declaration

    Swift

    func hyperbolicCosine() -> Self
  • hyperbolicTangent() Default implementation

    Returns the hyperbolic tangent of the value, rounded to a representable value.

    See also

    tanh(_:)
    Declaration

    Swift

    func hyperbolicTangent() -> Self
  • inverseHyperbolicSine()

    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
  • inverseHyperbolicCosine()

    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
  • inverseHyperbolicTangent()

    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
  • pow(_:_:) Extension method

    Returns the result of raising base to the power of exponent, rounded to a representable value (deprecated).

    Declaration

    Swift

    public static func pow(_ base: Self, _ exponent: Self) -> Self
    Parameters
    base

    The base to be raised to the power of exponent.

    exponent

    The exponent by which to raise base.

  • exp(_:) Extension method

    Returns the natural exponential of x, rounded to a representable value.

    The natural exponential of a value x is e (2.7182818…) raised to the power of x.

    Declaration

    Swift

    public static func exp(_ x: Self) -> Self
  • exp2(_:) Extension method

    Returns the binary exponential of x, rounded to a representable value.

    The binary exponential of a value x is 2 raised to the power of x.

    Declaration

    Swift

    public static func exp2(_ x: Self) -> Self
  • exp10(_:) Extension method

    Returns the common exponential of x, rounded to a representable value.

    The common exponential of a value x is 10 raised to the power of x.

    Declaration

    Swift

    public static func exp10(_ x: Self) -> Self
  • expm1(_:) Extension method

    Returns the result of subtracting one from the natural exponential of x, rounded to a representable value.

    The natural exponential of a value x is e (2.7182818…) raised to the power of x.

    This function is more accurate than .exp(x) - 1 for values of x close to zero.

    Declaration

    Swift

    public static func expm1(_ x: Self) -> Self
  • log(_:) Extension method

    Returns the natural (base e) logarithm of x, rounded to a representable value.

    Declaration

    Swift

    public static func log(_ x: Self) -> Self
  • log2(_:) Extension method

    Returns the binary (base 2) logarithm of x, rounded to a representable value.

    Declaration

    Swift

    public static func log2(_ x: Self) -> Self
  • log10(_:) Extension method

    Returns the common (base 10) logarithm of x, rounded to a representable value.

    Declaration

    Swift

    public static func log10(_ x: Self) -> Self
  • log1p(_:) Extension method

    Returns the natural (base e) logarithm of the result of adding one to x, rounded to a representable value.

    Declaration

    Swift

    public static func log1p(_ x: Self) -> Self
  • sqrt(_:) Extension method

    Returns the square root of x, rounded to a representable value.

    See also

    squareRoot()
    Declaration

    Swift

    public static func sqrt(_ x: Self) -> Self
  • cbrt(_:) Extension method

    Returns the cube root of x, rounded to a representable value.

    See also

    cubeRoot()
    Declaration

    Swift

    public static func cbrt(_ x: Self) -> Self
  • sin(_:) Extension method

    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
  • cos(_:) Extension method

    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
  • tan(_:) Extension method

    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
  • asin(_:) Extension method

    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
  • acos(_:) Extension method

    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
  • atan(_:) Extension method

    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
  • sinh(_:) Extension method

    Returns the hyperbolic sine of x, rounded to a representable value.

    See also

    hyperbolicSine()
    Declaration

    Swift

    public static func sinh(_ x: Self) -> Self
  • cosh(_:) Extension method

    Returns the hyperbolic cosine of x, rounded to a representable value.

    Declaration

    Swift

    public static func cosh(_ x: Self) -> Self
  • tanh(_:) Extension method

    Returns the hyperbolic tangent of x, rounded to a representable value.

    Declaration

    Swift

    public static func tanh(_ x: Self) -> Self
  • asinh(_:) Extension method

    Returns the principal value of the inverse hyperbolic sine of x, rounded to a representable value.

    Declaration

    Swift

    public static func asinh(_ x: Self) -> Self
  • acosh(_:) Extension method

    Returns the principal value of the inverse hyperbolic cosine of x, rounded to a representable value.

    Declaration

    Swift

    public static func acosh(_ x: Self) -> Self
  • atanh(_:) Extension method

    Returns the principal value of the inverse hyperbolic tangent of x, rounded to a representable value.

    Declaration

    Swift

    public static func atanh(_ x: Self) -> Self