struct BSON::Decimal128

Overview

128-bit decimal floating point.

NOTE This implementation has been mostly ported from https://github.com/mongodb/bson-ruby/blob/master/lib/bson/decimal128.rb.

Performance is bad because it relies on a string representation of the value.

See: https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.rst

Defined in:

Constant Summary

EXPONENT_OFFSET = 6176

Exponent offset.

INFINITY_MASK = 8646911284551352320_i64.to_big_i

Infinity mask.

INFINITY_REGEX = /^(\+|\-)?Inf(inity)?$/i

Regex matching a string representing positive or negative Infinity.

INFINITY_STRING = "Infinity"

String representing an Infinity value.

MAX_DIGITS_OF_PRECISION = 34

Maximum digits of precision.

MAX_EXPONENT = 6111

Maximum exponent.

MIN_EXPONENT = -6176

Minimum exponent.

NAN_MASK = 8935141660703064064_i64.to_big_i

NaN mask.

NAN_REGEX = /^(\-)?(S)?NaN$/i

Regex matching a string representing NaN.

NAN_STRING = "NaN"

String representing a NaN value.

SCIENTIFIC_EXPONENT_REGEX = /E\+?/i

Regex matching a scientific exponent.

SIGN_AND_DIGITS_REGEX = /^(\-)?(\S+)/

Regex for separating a negative sign from the significands.

SIGN_BIT_MASK = (1.to_big_i << 63)

Signed bit mask.

SIGNIFICAND_WITH_LEADING_ZEROS_REGEX = /(0*)(\d+)/

Regex for the fraction, including leading zeros.

SNAN_MASK = (1.to_big_i << 57)

SNaN mask.

TRAILING_ZEROS_REGEX = /[1-9]*(0+)$/

Regex for capturing trailing zeros.

TWO_HIGHEST_BITS_SET = (3.to_big_i << 61)

The two highest bits of the 64 high order bits.

VALID_DECIMAL128_STRING_REGEX = /^[\-\+]?(\d+(\.\d*)?|\.\d+)(E[\-\+]?\d+)?$/i

Regex for a valid decimal128 string format.

Constructors

Instance Method Summary

Constructor Detail

def self.new(significand : BigInt, exponent : Int32, is_negative : Bool) #

Convert parts representing a Decimal128 into the corresponding bits.


def self.new(string : String) #

def self.new(big_decimal : BigDecimal) #

def self.new(bytes : Bytes) #

Instance Method Detail

def bytes #

BSON byte representation.


def high : BigInt #

def infinity? #

def low : BigInt #

def nan? #

def negative? #

def to_big_d #

def to_canonical_extjson(builder : JSON::Builder) #

Serialize to a canonical extended json representation.

NOTE see https://github.com/mongodb/specifications/blob/master/source/extended-json.rst


def to_json(builder : JSON::Builder) #

def to_s(io : IO) #
Description copied from struct Struct

Same as #inspect(io).