Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
decimal.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <common/types.hpp>
4#include <cstdint>
5
10
12inline constexpr int64_t DECIMAL9_PER_FIXED = 1'000'000'000 / DOUBLE_MULTIPLIER;
13static_assert(DECIMAL9_PER_FIXED == 10);
14
18[[nodiscard]] inline constexpr bool from_decimal9(int64_t mantissa, int64_t &out) noexcept {
19 if (mantissa % DECIMAL9_PER_FIXED != 0) {
20 return false;
21 }
22 out = mantissa / DECIMAL9_PER_FIXED;
23 return true;
24}
25
29[[nodiscard]] inline constexpr int64_t to_decimal9(int64_t fixed) noexcept {
30 return fixed * DECIMAL9_PER_FIXED;
31}
32
33} // namespace slick::sim::utils
Conversions between wire decimals with a constant exponent of -9 (CME PRICE9, ICE Decimal9) and the s...
Definition decimal.hpp:9
constexpr int64_t to_decimal9(int64_t fixed) noexcept
The inverse.
Definition decimal.hpp:29
constexpr int64_t DECIMAL9_PER_FIXED
A 1e-9 mantissa is one decimal place finer than the simulator's scale.
Definition decimal.hpp:12
constexpr bool from_decimal9(int64_t mantissa, int64_t &out) noexcept
Returns false when the value has a digit at 1e-9.
Definition decimal.hpp:18
constexpr int32_t DOUBLE_MULTIPLIER
Definition types.hpp:29