libfxd 0.2.dev
A fixed-point library for C++.
Loading...
Searching...
No Matches
except.hpp File Reference
#include <concepts>
#include <cstdlib>
#include <stdexcept>
#include "concepts.hpp"
#include "error.hpp"
#include "detail/safe.hpp"
#include "detail/safe-div.hpp"
#include "detail/safe-mul.hpp"

Go to the source code of this file.

Namespaces

namespace  fxd
 This is the namespace where the entire library is defined.
 
namespace  fxd::except
 Throw on overflow.
 
namespace  fxd::except::down
 Round down, and throw on overflow.
 
namespace  fxd::except::up
 Round up, and throw on overflow.
 
namespace  fxd::except::zero
 Round to zero, and throw on overflow.
 

Macros

#define WRAP(expr)
 

Functions

void except (error e)
 Error handler that throws exceptions on error.
 
template<fixed_point Fxd, std::integral I>
constexpr Fxd from_raw (I val)
 Construct from raw value, throw on overflow.
 
template<fixed_point Dst, std::convertible_to< Dst > Src>
constexpr Dst make_fixed (Src src)
 Construct from numerical value, throw on overflow.
 
template<int Int, int Frac, typename Raw = detail::select_int_t<Int + Frac>, std::convertible_to< fixed< Int, Frac, Raw > > Src>
constexpr fixed< Int, Frac, Raw > make_fixed (Src src)
 Convenience overload.
 
template<int Int, int Frac, typename Raw = detail::select_uint_t<Int + Frac>, std::convertible_to< fixed< Int, Frac, Raw > > Src>
constexpr fixed< Int, Frac, Raw > make_ufixed (Src src)
 Convenience overload (unsigned version).
 
template<fixed_point Dst, fixed_point Src>
constexpr Dst fixed_cast (Src src)
 Convert between fxd::fixed types, throw on overflow.
 
template<int Int, int Frac, typename Raw = detail::select_int_t<Int + Frac>, fixed_point Src>
constexpr fixed< Int, Frac, Raw > fixed_cast (Src src)
 Convenience overload.
 
template<int Int, int Frac, typename Raw = detail::select_uint_t<Int + Frac>, fixed_point Src>
constexpr fixed< Int, Frac, Raw > ufixed_cast (Src src)
 Convenience overload (unsigned version).
 
template<std::integral I, fixed_point Fxd>
to_int (Fxd f)
 Convert to integer, throw on overflow.
 
template<fixed_point Fxd>
constexpr detail::select_int_for< Fxd::int_bits, typename Fxd::raw_type > to_int (Fxd f)
 Convert to the natural integer type, throw on overflow.
 
template<fixed_point Dst, std::convertible_to< Dst > Src>
constexpr Dst & assign (Dst &dst, Src src)
 Assignment, throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd & pre_inc (Fxd &f)
 Pre-increment (++f), throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd post_inc (Fxd &f)
 Post-increment (f++), throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd & pre_dec (Fxd &f)
 Pre-decrement (--f), throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd post_dec (Fxd &f)
 Post-decrement (f--), throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd negate (Fxd f)
 Negate, throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd add (Fxd a, Fxd b)
 Add, throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd sub (Fxd a, Fxd b)
 Subtract, throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd div (Fxd a, Fxd b)
 Divide rounding down, throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd mul (Fxd a, Fxd b)
 Multiply rounding down, throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd div (Fxd a, Fxd b)
 Divide rounding up, throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd mul (Fxd a, Fxd b)
 Multiply rounding up, throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd div (Fxd a, Fxd b)
 Divide rounding to zero, throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd mul (Fxd a, Fxd b)
 Multiply rounding to zero, throw on overflow.
 
template<fixed_point Fxd>
constexpr Fxd abs (Fxd f)
 Same as fxd::abs(), throw on overflow.
 

Macro Definition Documentation

◆ WRAP

#define WRAP (   expr)
Value:
do { \
auto result = detail::safe::expr; \
if (!result) \
except(result.error()); \
return *result; \
} while (false)

Definition at line 54 of file except.hpp.