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
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
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)
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)
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)

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.

Parameters:

  • significand (Integer)

    The significand.

  • exponent (Integer)

    The exponent.

  • is_negative (true, false)

    Whether the value is negative.

Returns:

  • (Array)

    Tuple of the low and high bits.

Since:

  • 4.2.0



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

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