8#ifndef LIBFXD_EXCEPT_HPP
9#define LIBFXD_EXCEPT_HPP
18#include "detail/safe.hpp"
19#include "detail/safe-div.hpp"
20#include "detail/safe-mul.hpp"
43 throw std::underflow_error{
"underflow"};
45 throw std::overflow_error{
"overflow"};
47 throw std::invalid_argument{
"not a number"};
49 throw std::logic_error{
"unknown error"};
56 auto result = detail::safe::expr; \
58 except(result.error()); \
69 template<fixed_point Fxd,
75 WRAP(from_raw<Fxd>(val));
81 std::convertible_to<Dst> Src>
86 WRAP(make_fixed<Dst>(src));
91 template<
int Int,
int Frac,
92 typename Raw = detail::select_int_t<Int + Frac>,
93 std::convertible_to<fixed<Int, Frac, Raw>> Src>
99 return except::make_fixed<Dst>(src);
104 template<
int Int,
int Frac,
105 typename Raw = detail::select_uint_t<Int + Frac>,
106 std::convertible_to<fixed<Int, Frac, Raw>> Src>
112 return except::make_fixed<Dst>(src);
123 WRAP(fixed_cast<Dst>(src));
128 template<
int Int,
int Frac,
129 typename Raw = detail::select_int_t<Int + Frac>,
136 return except::fixed_cast<Dst>(src);
141 template<
int Int,
int Frac,
142 typename Raw = detail::select_uint_t<Int + Frac>,
149 return except::fixed_cast<Dst>(src);
154 template<std::integral I,
164 template<fixed_po
int Fxd>
166 detail::select_int_for<Fxd::int_bits, typename Fxd::raw_type>
169 using I = detail::select_int_for<Fxd::int_bits, typename Fxd::raw_type>;
170 return except::to_int<I>(f);
176 std::convertible_to<Dst> Src>
182 return dst = except::make_fixed<Dst>(src);
187 template<fixed_po
int Fxd>
192 auto result = detail::safe::incremented(f);
200 template<fixed_po
int Fxd>
212 template<fixed_po
int Fxd>
217 auto result = detail::safe::decremented(f);
225 template<fixed_po
int Fxd>
237 template<fixed_po
int Fxd>
247 template<fixed_po
int Fxd>
258 template<fixed_po
int Fxd>
272 template<fixed_po
int Fxd>
283 template<fixed_po
int Fxd>
299 template<fixed_po
int Fxd>
310 template<fixed_po
int Fxd>
327 template<fixed_po
int Fxd>
338 template<fixed_po
int Fxd>
351 template<fixed_po
int Fxd>
Concept to match any fxd::fixed
constexpr Fxd mul(Fxd a, Fxd b)
Multiply rounding down, throw on overflow.
constexpr Fxd div(Fxd a, Fxd b)
Divide rounding down, throw on overflow.
constexpr Fxd mul(Fxd a, Fxd b)
Multiply rounding up, throw on overflow.
constexpr Fxd div(Fxd a, Fxd b)
Divide rounding up, throw on overflow.
constexpr Fxd mul(Fxd a, Fxd b)
Multiply rounding to zero, throw on overflow.
constexpr Fxd div(Fxd a, Fxd b)
Divide rounding to zero, throw on overflow.
constexpr Fxd abs(Fxd f)
Same as fxd::abs(), throw on overflow.
constexpr Fxd & pre_dec(Fxd &f)
Pre-decrement (--f), throw on overflow.
constexpr fixed< Int, Frac, Raw > ufixed_cast(Src src)
Convenience overload (unsigned version).
constexpr Fxd negate(Fxd f)
Negate, throw on overflow.
constexpr Fxd post_dec(Fxd &f)
Post-decrement (f--), throw on overflow.
constexpr Dst make_fixed(Src src)
Construct from numerical value, throw on overflow.
constexpr Fxd add(Fxd a, Fxd b)
Add, throw on overflow.
constexpr Dst & assign(Dst &dst, Src src)
Assignment, throw on overflow.
constexpr Fxd sub(Fxd a, Fxd b)
Subtract, throw on overflow.
void except(error e)
Error handler that throws exceptions on error.
constexpr Fxd from_raw(I val)
Construct from raw value, throw on overflow.
constexpr Fxd post_inc(Fxd &f)
Post-increment (f++), throw on overflow.
constexpr Fxd & pre_inc(Fxd &f)
Pre-increment (++f), throw on overflow.
constexpr fixed< Int, Frac, Raw > make_ufixed(Src src)
Convenience overload (unsigned version).
constexpr Dst fixed_cast(Src src) noexcept
Convert a fixed point to a different type of fixed point.
constexpr I to_int(Fxd f) noexcept
Convert to integer.
error
Error values reported by fxd::expect function.
The fixed-point class template.