module BSON::Decimal128::Builder
Helper module for parsing String
, Integer
, Float
, BigDecimal
, and Decimal128
objects into other objects.
@api private
@since 4.2.0
Constants
- INFINITY_MASK
-
Infinity mask.
@since 4.2.0
- NAN_MASK
-
NaN mask.
@since 4.2.0
- SIGN_BIT_MASK
-
Signed bit mask.
@since 4.2.0
- SNAN_MASK
-
SNaN mask.
@since 4.2.0
- TWO_HIGHEST_BITS_SET
-
The two highest bits of the 64 high order bits.
@since 4.2.0
Public Instance Methods
Source
# File lib/bson/decimal128/builder.rb, line 63 def parts_to_bits(significand, exponent, is_negative) validate_range!(exponent, significand) exponent = exponent + Decimal128::EXPONENT_OFFSET high = significand >> 64 low = (high << 64) ^ significand if high >> 49 == 1 high = high & 0x7fffffffffff high |= TWO_HIGHEST_BITS_SET high |= (exponent & 0x3fff) << 47 else high |= exponent << 49 end if is_negative high |= SIGN_BIT_MASK end [ low, high ] end
Convert parts representing a Decimal128
into the corresponding bits.
@param [ Integer
] significand The significand. @param [ Integer
] exponent The exponent. @param [ true, false ] is_negative Whether the value is negative.
@return [ Array
] Tuple of the low and high bits.
@since 4.2.0
Private Instance Methods
Source
# File lib/bson/decimal128/builder.rb, line 101 def valid_exponent?(exponent) exponent <= Decimal128::MAX_EXPONENT && exponent >= Decimal128::MIN_EXPONENT end
Source
# File lib/bson/decimal128/builder.rb, line 97 def valid_significand?(significand) significand.to_s.length <= Decimal128::MAX_DIGITS_OF_PRECISION end
Source
# File lib/bson/decimal128/builder.rb, line 87 def validate_range!(exponent, significand) unless valid_exponent?(exponent) raise Decimal128::InvalidRange.new end unless valid_significand?(significand) raise Decimal128::UnrepresentablePrecision.new end end