8#ifndef LIBFXD_OPERATORS_HPP
9#define LIBFXD_OPERATORS_HPP
46 template<fixed_point Fxd,
47 std::convertible_to<Fxd> T>
54 a.raw_value += Fxd{b}.raw_value;
60 template<fixed_point Fxd,
61 std::convertible_to<Fxd> T>
68 a.raw_value -= Fxd{b}.raw_value;
74 template<fixed_point Fxd,
75 std::convertible_to<Fxd> T>
76 requires (!std::integral<T>)
83 return a = zero::mul<Fxd>(a, b);
88 template<fixed_point Fxd,
102 template<fixed_point Fxd,
103 std::convertible_to<Fxd> T>
104 requires (!std::integral<T>)
111 return a = zero::div<Fxd>(a, b);
116 template<fixed_point Fxd,
135 template<fixed_po
int Fxd>
147 template<fixed_po
int Fxd>
159 template<fixed_po
int Fxd>
172 template<fixed_po
int Fxd>
191 template<fixed_po
int Fxd>
202 template<fixed_po
int Fxd>
208 return Fxd::from_raw(-a.raw_value);
215 requires (fixed_point<A> || fixed_point<B>)
217 std::common_type_t<A, B>
222 using Fxd = std::common_type_t<A, B>;
223 return Fxd::from_raw(Fxd{a}.raw_value
232 requires (fixed_point<A> || fixed_point<B>)
234 std::common_type_t<A, B>
239 using Fxd = std::common_type_t<A, B>;
240 return Fxd::from_raw(Fxd{a}.raw_value
247 template<fixed_point A,
250 std::common_type_t<A, B>
255 using Fxd = std::common_type_t<A, B>;
256 return zero::mul<Fxd>(a, b);
261 template<fixed_point Fxd,
269 return Fxd::from_raw(a.raw_value * b);
274 template<std::integral I,
281 return Fxd::from_raw(a * b.raw_value);
286 template<fixed_point Fxd,
287 std::floating_point Flt>
295 return zero::mul<Fxd>(a, b);
300 template<std::floating_point Flt,
309 return zero::mul<Fxd>(a, b);
315 template<fixed_point A,
318 std::common_type_t<A, B>
323 using Fxd = std::common_type_t<A, B>;
324 return zero::div<Fxd>(a, b);
329 template<fixed_point Fxd,
337 return Fxd::from_raw(a.raw_value / b);
342 template<std::integral I,
355 template<fixed_point Fxd,
356 std::floating_point Flt>
363 return zero::div<Fxd>(a, b);
368 template<std::floating_point Flt,
376 return zero::div<Fxd>(a, b);
386 template<
typename CharT,
389 std::basic_ostream<CharT, Traits>&
390 operator <<(std::basic_ostream<CharT, Traits>& out,
398 template<
typename CharT,
401 std::basic_istream<CharT, Traits>&
405 typename std::numeric_limits<Fxd>::float_type ff;
This is the namespace where the entire library is defined.
constexpr Fxd operator+(Fxd a) noexcept
Unary +.
constexpr Fxd & operator-=(Fxd &a, T b) noexcept
In-place subtraction.
std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &in, Fxd &f)
Input (by converting from a floatiung-point value).
constexpr Fxd & operator*=(Fxd &a, T b) noexcept
In-place multiplication.
constexpr std::common_type_t< A, B > operator*(A a, B b) noexcept
Multiply: fxd::fixed * fxd::fixed
constexpr Fxd operator-(Fxd a) noexcept
Negation.
std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &out, Fxd f)
Output (by converting to a floating-point value).
constexpr Fxd & operator++(Fxd &a) noexcept
Pre-increment.
constexpr Fxd & operator--(Fxd &a) noexcept
Pre-decrement.
constexpr Flt to_float(Fxd f) noexcept
Convert a fixed-point to a floating-point type, rounds to zero.
constexpr Fxd & operator+=(Fxd &a, T b) noexcept
In-place addition.
constexpr Fxd & operator/=(Fxd &a, T b) noexcept
In-place division.
constexpr std::common_type_t< A, B > operator/(A a, B b) noexcept
Divide: fxd::fixed / fxd::fixed