libfxd 0.2.dev
A fixed-point library for C++.
Loading...
Searching...
No Matches
fxd::except Namespace Reference

Throw on overflow. More...

Namespaces

namespace  down
 Round down, and throw on overflow.
 
namespace  up
 Round up, and throw on overflow.
 
namespace  zero
 Round to zero, and throw on overflow.
 

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 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.
 

Detailed Description

Throw on overflow.

Function Documentation

◆ abs()

constexpr Fxd abs ( Fxd  f)
constexpr

Same as fxd::abs(), throw on overflow.

Definition at line 354 of file except.hpp.

◆ add()

constexpr Fxd add ( Fxd  a,
Fxd  b 
)
constexpr

Add, throw on overflow.

Examples
closest-pair.cpp.

Definition at line 250 of file except.hpp.

◆ assign()

constexpr Dst & assign ( Dst &  dst,
Src  src 
)
constexpr

Assignment, throw on overflow.

Definition at line 179 of file except.hpp.

◆ except()

void except ( error  e)
inline

Error handler that throws exceptions on error.

All functions in fxd::except use this as an error handler. Possible exceptions are:

  • std::underflow_error on underflows;
  • std::overflow_error on overflows;
  • std::invalid_argument when NaN would be generated;

Definition at line 39 of file except.hpp.

◆ fixed_cast() [1/2]

constexpr Dst fixed_cast ( Src  src)
constexpr

Convert between fxd::fixed types, throw on overflow.

Definition at line 121 of file except.hpp.

◆ fixed_cast() [2/2]

constexpr fixed< Int, Frac, Raw > fixed_cast ( Src  src)
constexpr

Convenience overload.

Definition at line 133 of file except.hpp.

◆ from_raw()

constexpr Fxd from_raw ( val)
constexpr

Construct from raw value, throw on overflow.

Overflow happens if the represented value does not convert back to the argument's value.

Definition at line 73 of file except.hpp.

◆ make_fixed() [1/2]

constexpr Dst make_fixed ( Src  src)
constexpr

Construct from numerical value, throw on overflow.

Definition at line 84 of file except.hpp.

◆ make_fixed() [2/2]

constexpr fixed< Int, Frac, Raw > make_fixed ( Src  src)
constexpr

Convenience overload.

Definition at line 96 of file except.hpp.

◆ make_ufixed()

constexpr fixed< Int, Frac, Raw > make_ufixed ( Src  src)
constexpr

Convenience overload (unsigned version).

Definition at line 109 of file except.hpp.

◆ negate()

constexpr Fxd negate ( Fxd  f)
constexpr

Negate, throw on overflow.

Definition at line 240 of file except.hpp.

◆ post_dec()

constexpr Fxd post_dec ( Fxd &  f)
constexpr

Post-decrement (f--), throw on overflow.

Definition at line 228 of file except.hpp.

◆ post_inc()

constexpr Fxd post_inc ( Fxd &  f)
constexpr

Post-increment (f++), throw on overflow.

Definition at line 203 of file except.hpp.

◆ pre_dec()

constexpr Fxd & pre_dec ( Fxd &  f)
constexpr

Pre-decrement (--f), throw on overflow.

Definition at line 215 of file except.hpp.

◆ pre_inc()

constexpr Fxd & pre_inc ( Fxd &  f)
constexpr

Pre-increment (++f), throw on overflow.

Definition at line 190 of file except.hpp.

◆ sub()

constexpr Fxd sub ( Fxd  a,
Fxd  b 
)
constexpr

Subtract, throw on overflow.

Examples
closest-pair.cpp.

Definition at line 261 of file except.hpp.

◆ to_int() [1/2]

I to_int ( Fxd  f)

Convert to integer, throw on overflow.

Definition at line 157 of file except.hpp.

◆ to_int() [2/2]

constexpr detail::select_int_for< Fxd::int_bits, typename Fxd::raw_type > to_int ( Fxd  f)
constexpr

Convert to the natural integer type, throw on overflow.

Definition at line 167 of file except.hpp.

◆ ufixed_cast()

constexpr fixed< Int, Frac, Raw > ufixed_cast ( Src  src)
constexpr

Convenience overload (unsigned version).

Definition at line 146 of file except.hpp.