# 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.

• ``` init() ```

Creates a new zero-initialized Decimal128.

• ``` init(value:) ```

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.

• ``` init(number:) ```

Converts the given number to a Decimal128.

This initializer cannot fail and is never lossy.

• ``` init(string:) ```

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`.

• ``` init(from:) ```

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

• ``` encode(to:) ```

Encodes this Decimal128 to the given encoder.

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

• ``` init(integerLiteral:) ```

Creates a new Decimal128 from the given integer literal.

• ``` init(floatLiteral:) ```

Creates a new Decimal128 from the given float literal.

• ``` init(stringLiteral:) ```

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.

• ``` init(exactly:) ```

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:

• ``` Magnitude ```

A type that can represent the absolute value of Decimal128

• ``` magnitude ```

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.

• ``` Stride ```

A type that represents the distance between two values.

• ``` distance(to:) ```

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

• ``` advanced(by:) ```

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.

• ``` isSignaling ```

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

• ``` isSignalingNaN ```

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