Module: BSON::Decimal128::Builder Private

Extended by:
Builder
Included in:
Builder
Defined in:
lib/bson/decimal128/builder.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Helper module for parsing String, Integer, Float, BigDecimal, and Decimal128 objects into other objects.

Since:

  • 4.2.0

Defined Under Namespace

Classes: FromBigDecimal, FromString, ToString

Constant Summary collapse

INFINITY_MASK =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Infinity mask.

Since:

  • 4.2.0

0x7800000000000000.freeze
NAN_MASK =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

NaN mask.

Since:

  • 4.2.0

0x7c00000000000000.freeze
SNAN_MASK =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

SNaN mask.

Since:

  • 4.2.0

(1 << 57).freeze
SIGN_BIT_MASK =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Signed bit mask.

Since:

  • 4.2.0

(1 << 63).freeze
TWO_HIGHEST_BITS_SET =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The two highest bits of the 64 high order bits.

Since:

  • 4.2.0

(3 << 61).freeze

Instance Method Summary collapse

Instance Method Details

#parts_to_bits(significand, exponent, is_negative) ⇒ Array

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert parts representing a Decimal128 into the corresponding bits.

Since:

  • 4.2.0


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bson/decimal128/builder.rb', line 62

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