Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
math.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cassert>
4#include <cstdint>
5#if defined(_MSC_VER) && defined(_M_X64)
6#include <intrin.h>
7#elif !defined(__SIZEOF_INT128__)
8#include <common/types.hpp>
9#endif
10
11namespace slick::sim::utils {
12
19inline uint64_t mul_div_floor(uint64_t a, uint64_t b, uint64_t c) noexcept {
20 assert(c != 0 && b <= c);
21#if defined(_MSC_VER) && defined(_M_X64)
22 uint64_t hi;
23 const uint64_t lo = _umul128(a, b, &hi);
24 uint64_t rem;
25 return _udiv128(hi, lo, c, &rem);
26#elif defined(__SIZEOF_INT128__)
27 __extension__ typedef unsigned __int128 u128; // __extension__: no -Wpedantic warning
28 return static_cast<uint64_t>(static_cast<u128>(a) * b / c);
29#else
30 return static_cast<uint64_t>(cum_value_t(a) * b / c);
31#endif
32}
33
34} // 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
uint64_t mul_div_floor(uint64_t a, uint64_t b, uint64_t c) noexcept
floor(a * b / c), with the product held at 128 bits.
Definition math.hpp:19
boost::multiprecision::uint128_t cum_value_t
Definition types.hpp:25