Decimal128

@objc(RealmSwiftDecimal128)
public final class Decimal128 : RLMDecimal128, Decodable, @unchecked Sendable
extension Decimal128: BSON
extension Decimal128: Encodable
extension Decimal128: ExpressibleByIntegerLiteral
extension Decimal128: ExpressibleByFloatLiteral
extension Decimal128: ExpressibleByStringLiteral
extension Decimal128: Comparable
extension Decimal128: Numeric
extension Decimal128: _QueryNumeric
extension Decimal128: _RealmCollectionValueInsideOptional
extension Decimal128: MinMaxType
extension Decimal128: AddableType
extension Decimal128: SortableType

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.

    Declaration

    Swift

    public override required init()
  • 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.

    Declaration

    Swift

    public override required init(value: Any)

    Parameters

    value

    The value to convert to a Decimal128.

  • Converts the given number to a Decimal128.

    This initializer cannot fail and is never lossy.

    Declaration

    Swift

    public override required init(number: NSNumber)

    Parameters

    number

    The number to convert to a Decimal128.

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

    Declaration

    Swift

    public override required init(string: String) throws

    Parameters

    string

    The string to parse.

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

    Declaration

    Swift

    public required init(from decoder: Decoder) throws

    Parameters

    decoder

    The decoder to read data from.

  • min

    The minimum value for Decimal128

    Declaration

    Swift

    public static var min: Decimal128 { get }
  • max

    The maximum value for Decimal128

    Declaration

    Swift

    public static var max: Decimal128 { get }
  • Encodes this Decimal128 to the given encoder.

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

    Declaration

    Swift

    public func encode(to encoder: Encoder) throws

    Parameters

    encoder

    The encoder to write data to.

  • Creates a new Decimal128 from the given integer literal.

    Declaration

    Swift

    public convenience init(integerLiteral value: Int64)
  • Creates a new Decimal128 from the given float literal.

    Declaration

    Swift

    public convenience init(floatLiteral value: Double)
  • Creates a new Decimal128 from the given string literal.

    Aborts if the string cannot be parsed as a Decimal128.

    Declaration

    Swift

    public convenience init(stringLiteral value: String)
  • Returns a Boolean value indicating whether two decimal128 values are equal.

    Declaration

    Swift

    public static func == (lhs: Decimal128, rhs: Decimal128) -> Bool

    Parameters

    lhs

    A Decimal128 value to compare.

    rhs

    Another Decimal128 value to compare.

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

    Declaration

    Swift

    public static func < (lhs: Decimal128, rhs: Decimal128) -> Bool

    Parameters

    lhs

    A Decimal128 value to compare.

    rhs

    Another Decimal128 value to compare.

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

    Declaration

    Swift

    public static func <= (lhs: Decimal128, rhs: Decimal128) -> Bool

    Parameters

    lhs

    A Decimal128 value to compare.

    rhs

    Another Decimal128 value to compare.

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

    Declaration

    Swift

    public static func >= (lhs: Decimal128, rhs: Decimal128) -> Bool

    Parameters

    lhs

    A Decimal128 value to compare.

    rhs

    Another Decimal128 value to compare.

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

    Declaration

    Swift

    public static func > (lhs: Decimal128, rhs: Decimal128) -> Bool

    Parameters

    lhs

    A Decimal128 value to compare.

    rhs

    Another Decimal128 value to compare.

  • 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:

    Declaration

    Swift

    public convenience init?<T>(exactly source: T) where T : BinaryInteger

    Parameters

    source

    A value to convert to this type of integer.

  • A type that can represent the absolute value of Decimal128

    Declaration

    Swift

    public typealias Magnitude = Decimal128
  • The magnitude of this Decimal128.

    Declaration

    Swift

    public var magnitude: Magnitude { get }
  • Adds two decimal128 values and produces their sum.

    Declaration

    Swift

    public static func + (lhs: Decimal128, rhs: Decimal128) -> Decimal128

    Parameters

    lhs

    The first Decimal128 value to add.

    rhs

    The second Decimal128 value to add.

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

    Declaration

    Swift

    public static func - (lhs: Decimal128, rhs: Decimal128) -> Decimal128

    Parameters

    lhs

    A Decimal128 value.

    rhs

    The Decimal128 value to subtract from lhs.

  • Multiplies two Decimal128 values and produces their product.

    Declaration

    Swift

    public static func * (lhs: Decimal128, rhs: Decimal128) -> Decimal128

    Parameters

    lhs

    The first value to multiply.

    rhs

    The second value to multiply.

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

    Declaration

    Swift

    public static func *= (lhs: inout Decimal128, rhs: Decimal128)

    Parameters

    lhs

    The first value to multiply.

    rhs

    The second value to multiply.

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

    Declaration

    Swift

    public static func / (lhs: Decimal128, rhs: Decimal128) -> Decimal128

    Parameters

    lhs

    The Decimal128 value to divide.

    rhs

    The Decimal128 value to divide lhs by. rhs must not be zero.

  • A type that represents the distance between two values.

    Declaration

    Swift

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

    Declaration

    Swift

    public func distance(to other: Decimal128) -> Decimal128

    Parameters

    other

    The Decimal128 value to calculate the distance to.

    Return Value

    The distance from this value to other.

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

    Declaration

    Swift

    public func advanced(by n: Decimal128) -> Decimal128

    Parameters

    n

    The distance to advance this Decimal128.

    Return Value

    A Decimal128 that is offset from this value by n.

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

    Declaration

    Swift

    public var isSignaling: Bool { get }
  • true if self is a signaling NaN, false otherwise.

    Declaration

    Swift

    public var isSignalingNaN: Bool { get }