34template <
typename RawType,
unsigned int Decimals>
36 static_assert(std::is_unsigned_v<RawType>,
"Price raw storage must be an unsigned integer");
42 static constexpr unsigned int decimals = Decimals;
55 [[nodiscard]]
constexpr auto raw() const noexcept ->
raw_type {
return m_raw; }
63 for (
unsigned int exponent {0}; exponent < Decimals; ++exponent) {
72 [[nodiscard]]
constexpr auto to_double() const noexcept ->
double {
73 return static_cast<double>(m_raw) /
static_cast<double>(
divisor());
79 [[nodiscard]]
auto to_string() const -> std::
string {
80 return std::format(
"{:.{}f}",
to_double(), Decimals);
126template <
typename RawType,
unsigned int Decimals>
127struct std::formatter<
itch::BasicPrice<RawType, Decimals>> : std::formatter<double> {
135 return std::formatter<double>::format(
price.to_double(), ctx);
A strongly typed fixed-point price carrying its own decimal scale.
static constexpr auto divisor() noexcept -> raw_type
The scale's divisor, i.e.
constexpr auto to_double() const noexcept -> double
The price as a floating-point value (raw / 10^Decimals).
constexpr BasicPrice() noexcept=default
Constructs a zero-valued price at this scale.
constexpr auto raw() const noexcept -> raw_type
The underlying raw integer value, exactly as it appears on the wire.
auto to_string() const -> std::string
The price as a fixed-precision decimal string.
static constexpr unsigned int decimals
The number of implied decimal places for this price scale.
friend constexpr auto operator<=>(BasicPrice, BasicPrice) noexcept=default
Orders two prices of the same scale by raw value.
friend constexpr auto operator==(BasicPrice, BasicPrice) noexcept -> bool=default
Compares two prices of the same scale for equality by raw value.
constexpr auto make_mwcb_price(std::uint64_t raw_value) noexcept -> MwcbPrice
Wraps a raw 8-decimal MWCB price value in the typed MwcbPrice.
constexpr auto make_price(std::uint32_t raw_value) noexcept -> StandardPrice
Wraps a raw 4-decimal price value in the typed StandardPrice.