8#ifndef LIBFXD_EXPECT_HPP
9#define LIBFXD_EXPECT_HPP
16#include "detail/safe.hpp"
17#include "detail/safe-div.hpp"
18#include "detail/safe-mul.hpp"
19#include "detail/types.hpp"
27 using maybe = detail::expected<T, error>;
30 using detail::safe::from_raw;
32 using detail::safe::make_fixed;
35 template<
int Int,
int Frac,
36 typename Raw = detail::select_int_t<Int + Frac>,
37 std::convertible_to<fixed<Int, Frac, Raw>> Src>
43 return expect::make_fixed<Dst>(src);
48 template<
int Int,
int Frac,
49 typename Raw = detail::select_uint_t<Int + Frac>,
50 std::convertible_to<fixed<Int, Frac, Raw>> Src>
52 maybe<fixed<Int, Frac, Raw>>
56 return expect::make_fixed<Dst>(src);
60 using detail::safe::fixed_cast;
64 template<
int Int,
int Frac,
65 typename Raw = fxd::detail::select_int_t<Int + Frac>,
69 maybe<fixed<Int, Frac, Raw>>
74 return expect::fixed_cast<Dst>(src);
79 template<
int Int,
int Frac,
80 typename Raw = fxd::detail::select_uint_t<Int + Frac>,
84 maybe<fixed<Int, Frac, Raw>>
89 return expect::fixed_cast<Dst>(src);
93 using detail::safe::to_int;
102 std::convertible_to<Dst> Src>
109 auto result = expect::make_fixed<Dst>(src);
112 return dst = *result;
121 template<fixed_po
int Fxd>
127 auto result = detail::safe::incremented(f);
135 template<fixed_po
int Fxd>
154 template<fixed_po
int Fxd>
160 auto result = detail::safe::decremented(f);
168 template<fixed_po
int Fxd>
182 using detail::safe::negate;
184 using detail::safe::add;
186 using detail::safe::sub;
191 using detail::safe::down::div;
193 using detail::safe::down::mul;
201 using detail::safe::up::div;
203 using detail::safe::up::mul;
212 using detail::safe::zero::div;
214 using detail::safe::zero::mul;
219 using detail::safe::abs;
Concept to match any fxd::fixed
Return fxd::expect::maybe<...> result.
constexpr maybe< fixed< Int, Frac, Raw > > ufixed_cast(Src src) noexcept
Convenience overload (unsigned version).
constexpr maybe< Dst > assign(Dst &dst, Src src) noexcept
Assignment.
constexpr maybe< fixed< Int, Frac, Raw > > make_ufixed(Src src)
Convenience overload (unsigned version).
detail::expected< T, error > maybe
Alias to std::expected, or an equivalent implementation.
constexpr maybe< Fxd > pre_dec(Fxd &f) noexcept
Pre-decrement (--f).
constexpr maybe< Fxd > post_inc(Fxd &f) noexcept
Post-increment (f++).
constexpr maybe< Fxd > post_dec(Fxd &f) noexcept
Post-decrement (f--).
constexpr maybe< Fxd > pre_inc(Fxd &f) noexcept
Pre-increment (++f).
constexpr Dst fixed_cast(Src src) noexcept
Convert a fixed point to a different type of fixed point.
The fixed-point class template.