8#include "string_tag.hpp"
15template<
typename T,
int M>
18 static constexpr int multiplier = M;
29 template<
typename O, std::enable_if_t<std::is_
floating_po
int_v<O>,
int> = 0>
30 explicit constexpr fixed(O other) noexcept :
31 value(
static_cast<T
>(other * M)) {
38 template<
typename O, std::enable_if_t<std::is_
integral_v<O>,
int> = 0>
39 explicit constexpr fixed(O other) noexcept :
40 value(
static_cast<T
>(other) * M) {
50 template<
typename O, std::enable_if_t<std::is_
floating_po
int_v<O>,
int> = 0>
51 constexpr fixed &operator=(O other)
noexcept {
52 value =
static_cast<T
>(other * M);
60 template<
typename O, std::enable_if_t<std::is_
integral_v<O>,
int> = 0>
61 constexpr fixed &operator=(O other)
noexcept {
62 value =
static_cast<T
>(other) * M;
71 value =
static_cast<T
>(stod(other) * M);
79 template<
typename O, std::enable_if_t<std::is_
floating_po
int_v<O>,
int> = 0>
80 explicit operator O ()
const noexcept {
81 return static_cast<O
>(value) / M;
84 template<
typename O, std::enable_if_t<std::is_
integral_v<O>,
int> = 0>
85 explicit operator O ()
const noexcept {
86 return static_cast<O
>(value / M);
90 return std::format(
"{}",
static_cast<double>(value) / M);
93 static fixed fromValue(T value)
noexcept {
101template<
typename T,
int M>
inline bool operator!=(fixed<T,M>
const &lhs, fixed<T,M>
const &rhs) {
return lhs.value != rhs.value; }
102template<
typename T,
int M>
inline bool operator<(fixed<T,M>
const &lhs, fixed<T,M>
const &rhs) {
return lhs.value < rhs.value; }
103template<
typename T,
int M>
inline bool operator>(fixed<T,M>
const &lhs, fixed<T,M>
const &rhs) {
return lhs.value > rhs.value; }
104template<
typename T,
int M>
inline bool operator<=(fixed<T,M>
const &lhs, fixed<T,M>
const &rhs) {
return lhs.value <= rhs.value; }
105template<
typename T,
int M>
inline bool operator>=(fixed<T,M>
const &lhs, fixed<T,M>
const &rhs) {
return lhs.value >= rhs.value; }
107template<
typename T,
int M>
108fixed<T,M> operator+(fixed<T,M>
const &lhs, fixed<T,M>
const &rhs)
110 return fixed<T,M>::fromValue(lhs.value + rhs.value);
113template<
typename T,
int M>
114fixed<T,M> operator-(fixed<T,M>
const &lhs, fixed<T,M>
const &rhs)
116 return fixed<T,M>::fromValue(lhs.value - rhs.value);
119template<
typename T,
int M>
125template<
typename T,
int M>
128 return lhs << rhs.string();
131using money = fixed<safe_int<int64_t>,100>;
constexpr bool operator==(alignment lhs, horizontal_alignment rhs) noexcept
Check if the horizontal alignments are equal.
Definition alignment.hpp:136