Library: MongoDB
Package: MongoDB
Header: Poco/MongoDB/Decimal128.h
Description
Represents an IEEE 754-2008 decimal128 floating-point value (BSON TypeId 0x13, available since MongoDB 3.4). Used wherever exact decimal representation matters — currency, ledger entries, scientific data — since binary double cannot represent 0.1 exactly.
Storage is two Poco::UInt64 halves matching the BSON wire format (16 bytes, little-endian, low half first then high half). The class supports BSON serialization, canonical string conversion per IEEE 754-2008 Section 5.12.4, parsing simple decimal literals, and equality comparison. It does not implement decimal arithmetic; users who need to operate on values are expected to round-trip through std::string or use an external decimal-arithmetic library.
Member Summary
Member Functions: fromString, high, isInfinite, isNaN, isNegative, low, nan, negativeInfinity, negativeZero, operator !=, operator ==, positiveInfinity, positiveZero, toString
Types Aliases
Ptr
using Ptr = Poco::SharedPtr < Decimal128 >;
Constructors
Decimal128
Decimal128();
Creates a Decimal128 representing positive zero (0E0).
Decimal128
Decimal128(
Poco::UInt64 low,
Poco::UInt64 high
);
Creates a Decimal128 from the raw 128 bits, expressed as low and high 64-bit halves matching the on-wire layout.
Destructor
~Decimal128
~Decimal128() = default;
Member Functions
fromString
static Decimal128 fromString(
const std::string & s
);
Parses a decimal string into a Decimal128. Accepts the canonical forms produced by toString(): "NaN" (case insensitive), "Infinity" / "-Infinity" / "Inf" / "-Inf", and finite decimal literals with optional sign, optional fractional part, and optional exponent ("E"/"e" prefix). Throws Poco::SyntaxException on malformed input or Poco::RangeException when the coefficient exceeds 34 decimal digits or the exponent is out of the decimal128 range.
high
[[nodiscard]]
Poco::UInt64 high() const noexcept;
isInfinite
[[nodiscard]]
bool isInfinite() const noexcept;
isNaN
[[nodiscard]]
bool isNaN() const noexcept;
isNegative
[[nodiscard]]
bool isNegative() const noexcept;
Includes -0, -Inf and -NaN.
low
[[nodiscard]]
Poco::UInt64 low() const noexcept;
nan
static Decimal128 nan();
negativeInfinity
static Decimal128 negativeInfinity();
negativeZero
static Decimal128 negativeZero();
operator !=
bool operator != (
const Decimal128 & other
) const noexcept;
operator ==
bool operator == (
const Decimal128 & other
) const noexcept;
positiveInfinity
static Decimal128 positiveInfinity();
positiveZero
static Decimal128 positiveZero();
toString
[[nodiscard]]
std::string toString() const;
Returns the canonical decimal string per IEEE 754-2008 Section 5.12.4: special values render as "NaN", "Infinity", "-Infinity"; finite values render in scientific or non-scientific notation depending on the adjusted exponent.