Decimal128

A 128-bit IEEE 754-2008 decimal floating point number.

This type is similar to Swift’s built-in Decimal type, but allocates bits differently, resulting in a different representable range. (NS)Decimal stores a significand of up to 38 digits long and an exponent from -128 to 127, while this type stores up to 34 digits of significand and an exponent from -6143 to 6144.

  • Creates a new zero-initialized Decimal128.

  • Converts the given value to a Decimal128.

    The following types can be converted to Decimal128:

    • Int (of any size)
    • Float
    • Double
    • String
    • NSNumber
    • Decimal

    Passing a value with a type not in this list is a fatal error. Passing a string which cannot be parsed as a valid Decimal128 is a fatal error.

  • Converts the given number to a Decimal128.

    This initializer cannot fail and is never lossy.

  • Parse the given string as a Decimal128.

    This initializer never throws and is marked as throws only because removing it is a breaking change. Strings which cannot be parsed as a Decimal128 return a value where isNaN is true.

  • Creates a new Decimal128 by decoding from the given decoder.

    This initializer throws an error if the decoder is invalid or does not decode to a value which can be converted to Decimal128.

  • min

    The mininum value for Decimal128

  • max

    The maximum value for Decimal128

  • Encodes this Decimal128 to the given encoder.

    This function throws an error if the given encoder is unable to encode a string.

  • Creates a new Decimal128 from the given integer literal.

  • Creates a new Decimal128 from the given float literal.

  • Creates a new Decimal128 from the given string literal.

    Aborts if the string cannot be parsed as a Decimal128.

  • Returns a Boolean value indicating whether two decimal128 values are equal.

  • Returns a Boolean value indicating whether the decimal128 value of the first argument is less than that of the second argument.

  • Returns a Boolean value indicating whether the decimal128 value of the first argument is less than or equal to that of the second argument.

  • Returns a Boolean value indicating whether the decimal128 value of the first argument is greater than or equal to that of the second argument.

  • Returns a Boolean value indicating whether the decimal128 value of the first argument is greater than that of the second argument.

  • Creates a new instance from the given integer, if it can be represented exactly.

    If the value passed as source is not representable exactly, the result is nil. In the following example, the constant x is successfully created from a value of 100, while the attempt to initialize the constant y from 1_000 fails because the Int8 type can represent 127 at maximum:

  • A type that can represent the absolute value of Decimal128

  • The magnitude of this Decimal128.

  • Adds two decimal128 values and produces their sum.

  • Subtracts one Decimal128 value from another and produces their difference.

  • Multiplies two Decimal128 values and produces their product.

  • Multiplies two values and stores the result in the left-hand-side variable.

  • Returns the quotient of dividing the first Decimal128 value by the second.

  • A type that represents the distance between two values.

  • Returns the distance from this Decimal128 to the given value, expressed as a stride.

  • Returns a Decimal128 that is offset the specified distance from this value.

    Use the advanced(by:) method in generic code to offset a value by a specified distance. If you’re working directly with numeric values, use the addition operator (+) instead of this method.

  • true if self is a signaling NaN, false otherwise.

  • true if self is a signaling NaN, false otherwise.