21 constexpr static int multiplier = M;
27 fixed(fixed
const &) =
default;
28 fixed &operator=(fixed
const &) =
default;
29 fixed(fixed &&) =
default;
30 fixed &operator=(fixed &&) =
default;
32 explicit constexpr fixed(std::floating_point
auto other) noexcept : value(
static_cast<T
>(other * M))
37 explicit constexpr fixed(std::integral
auto other) noexcept : value(
static_cast<T
>(other) * M)
42 explicit fixed(
std::string const &other) : fixed(stod(other)) {}
44 constexpr fixed &operator=(std::floating_point
auto other)
noexcept
46 value =
static_cast<T
>(other * M);
51 constexpr fixed &operator=(std::integral
auto other)
noexcept
53 value =
static_cast<T
>(other) * M;
60 value =
static_cast<T
>(stod(other) * M);
65 template<std::
floating_po
int O>
66 explicit operator O()
const noexcept
68 return static_cast<O
>(value) / M;
71 template<std::
integral O>
72 explicit operator O()
const noexcept
74 return static_cast<O
>(value / M);
79 return std::format(
"{}",
static_cast<double>(value) / M);
82 static fixed from_raw_value(T value)
noexcept
89 [[nodiscard]]
constexpr friend bool operator==(fixed
const &lhs, fixed
const &rhs)
noexcept
91 return lhs.value == rhs.value;
94 [[nodiscard]]
constexpr friend auto operator<=>(fixed
const &lhs, fixed
const &rhs)
noexcept
96 return lhs.value <=> rhs.value;
99 [[nodiscard]]
constexpr friend fixed operator+(fixed
const &lhs, fixed
const &rhs)
noexcept
101 return fixed<T, M>::from_raw_value(lhs.value + rhs.value);
104 [[nodiscard]]
constexpr friend fixed operator-(fixed
const &lhs, fixed
const &rhs)
noexcept
106 return fixed<T, M>::from_raw_value(lhs.value - rhs.value);
109 [[nodiscard]]
friend std::string to_string(fixed
const v)
116 return lhs << rhs.string();