Class BsonDecimal128

java.lang.Object
org.apache.juneau.marshall.bson.BsonDecimal128

public final class BsonDecimal128 extends Object
IEEE 754-2008 Decimal128 BID (Binary Integer Decimal) encoding for BSON.

Supports conversion between BigDecimal and the 16-byte BSON Decimal128 format. Used by BsonSerializer and BsonParser for decimal values.

See Also:
  • Method Details

    • fromIEEE754BIDEncoding

      public static BsonDecimal128 fromIEEE754BIDEncoding(long high, long low)
      Creates a Decimal128 from the given high and low 64-bit values (IEEE 754-2008 BID encoding).
      Parameters:
      high - The high-order 64 bits.
      low - The low-order 64 bits.
      Returns:
      The Decimal128 instance.
    • fromBigDecimal

      public static BsonDecimal128 fromBigDecimal(BigDecimal value)
      Creates a Decimal128 from the given BigDecimal.
      Parameters:
      value - The decimal value.
      Must not be null.
      Returns:
      The Decimal128 instance.
      Throws:
      NumberFormatException - If the value is out of Decimal128 range.
    • getHigh

      public long getHigh()
      Returns the high-order 64 bits.
      Returns:
      The high bits.
    • getLow

      public long getLow()
      Returns the low-order 64 bits.
      Returns:
      The low bits.
    • toBigDecimal

      Converts to BigDecimal.
      Returns:
      The equivalent BigDecimal.
      Throws:
      ArithmeticException - If the value is NaN, Infinity, or negative zero.
    • toBigDecimalOrNull

      Converts to BigDecimal, normalizing the special IEEE-754 values that have no BigDecimal representation.

      Unlike toBigDecimal(), this never throws: NaN and ±Infinity (both valid on the BSON wire and emitted by MongoDB) map to null, and negative zero maps to a finite zero. Used by the parser so adversarial/MongoDB-sourced special decimals fail soft instead of aborting the whole parse with an unchecked ArithmeticException.

      Returns:
      The equivalent BigDecimal, or null if the value is NaN or Infinity.