Package org.apache.juneau.marshall.bson
Class BsonDecimal128
java.lang.Object
org.apache.juneau.marshall.bson.BsonDecimal128
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 Summary
Modifier and TypeMethodDescriptionstatic BsonDecimal128fromBigDecimal(BigDecimal value) Creates a Decimal128 from the given BigDecimal.static BsonDecimal128fromIEEE754BIDEncoding(long high, long low) Creates a Decimal128 from the given high and low 64-bit values (IEEE 754-2008 BID encoding).longgetHigh()Returns the high-order 64 bits.longgetLow()Returns the low-order 64 bits.Converts to BigDecimal.Converts to BigDecimal, normalizing the special IEEE-754 values that have no BigDecimal representation.
-
Method Details
-
fromIEEE754BIDEncoding
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
Creates a Decimal128 from the given BigDecimal.- Parameters:
value- The decimal value.
Must not benull .- Returns:
- The Decimal128 instance.
- Throws:
NumberFormatException- If the value is out of Decimal128 range.
-
getHigh
Returns the high-order 64 bits.- Returns:
- The high bits.
-
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 tonull , 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 uncheckedArithmeticException.- Returns:
- The equivalent BigDecimal, or
null if the value is NaN or Infinity.
-