19 static constexpr int multiplier = M;
25 fixed(fixed
const &) =
default;
26 fixed &operator=(fixed
const &) =
default;
27 fixed(fixed &&) =
default;
28 fixed &operator=(fixed &&) =
default;
30 explicit constexpr fixed(std::floating_point
auto other) noexcept : value(
static_cast<T
>(other * M))
35 explicit constexpr fixed(std::integral
auto other) noexcept : value(
static_cast<T
>(other) * M)
40 explicit fixed(
std::string const &other) : fixed(stod(other)) {}
42 constexpr fixed &operator=(std::floating_point
auto other)
noexcept
44 value =
static_cast<T
>(other * M);
49 constexpr fixed &operator=(std::integral
auto other)
noexcept
51 value =
static_cast<T
>(other) * M;
58 value =
static_cast<T
>(stod(other) * M);
63 template<std::
floating_po
int O>
64 explicit operator O()
const noexcept
66 return static_cast<O
>(value) / M;
69 template<std::
integral O>
70 explicit operator O()
const noexcept
72 return static_cast<O
>(value / M);
77 return std::format(
"{}",
static_cast<double>(value) / M);
80 static fixed from_raw_value(T value)
noexcept
87 [[nodiscard]]
constexpr friend bool operator==(fixed
const &lhs, fixed
const &rhs)
noexcept
89 return lhs.value == rhs.value;
92 [[nodiscard]]
constexpr friend auto operator<=>(fixed
const &lhs, fixed
const &rhs)
noexcept
94 return lhs.value <=> rhs.value;
97 [[nodiscard]]
constexpr friend fixed operator+(fixed
const &lhs, fixed
const &rhs)
noexcept
99 return fixed<T, M>::from_raw_value(lhs.value + rhs.value);
102 [[nodiscard]]
constexpr friend fixed operator-(fixed
const &lhs, fixed
const &rhs)
noexcept
104 return fixed<T, M>::from_raw_value(lhs.value - rhs.value);
107 [[nodiscard]]
friend std::string to_string(fixed
const v)
114 return lhs << rhs.string();
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:199