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

Clamp on overflow. More...

Namespaces

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

Functions

template<typename T >
constexpr T saturate (error e) noexcept
 Error handler that clamps the value on error.
 
template<fixed_point Fxd, std::integral I>
constexpr Fxd from_raw (I val) noexcept
 Construct from raw value, clamp on overflow.
 
template<fixed_point Dst, std::convertible_to< Dst > Src>
constexpr Dst make_fixed (Src src) noexcept
 Construct from numerical value, clamp on overflow.
 
template<unsigned_fixed_point Dst, std::convertible_to< Dst > Src>
constexpr Dst make_ufixed (Src src) noexcept
 Construct from numerical value, clamp on overflow (unsigned version).
 
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) noexcept
 Convenience overload.
 
template<fixed_point Dst, fixed_point Src>
constexpr Dst fixed_cast (Src src) noexcept
 Convert between fxd::fixed types, clamp 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) noexcept
 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) noexcept
 Convenience overload (unsigned version).
 
template<std::integral I, fixed_point Fxd>
constexpr I to_int (Fxd f) noexcept
 Convert to integer, clamp 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, clamp on overflow.
 
template<fixed_point Dst, std::convertible_to< Dst > Src>
constexpr Dst & assign (Dst &dst, Src src) noexcept
 Assignment, clamp on overflow.
 
template<fixed_point Fxd>
constexpr Fxd & pre_inc (Fxd &f) noexcept
 Pre-increment (++f), clamp on overflow.
 
template<fixed_point Fxd>
constexpr Fxd post_inc (Fxd &f) noexcept
 Post-increment (f++), clamp on overflow.
 
template<fixed_point Fxd>
constexpr Fxd & pre_dec (Fxd &f) noexcept
 Pre-decrement (--f), clamp on overflow.
 
template<fixed_point Fxd>
constexpr Fxd post_dec (Fxd &f) noexcept
 Post-decrement (f--), clamp on overflow.
 
template<fixed_point Fxd>
constexpr Fxd negate (Fxd f) noexcept
 Negate, clamp on overflow.
 
template<fixed_point Fxd>
constexpr Fxd add (Fxd a, Fxd b) noexcept
 Add, clamp on overflow.
 
template<fixed_point Fxd>
constexpr Fxd sub (Fxd a, Fxd b) noexcept
 Subtract, clamp on overflow.
 
template<fixed_point Fxd>
constexpr Fxd div (Fxd a, Fxd b) noexcept
 Divide rounding to zero, clamp on overflow.
 
template<fixed_point Fxd>
constexpr Fxd mul (Fxd a, Fxd b) noexcept
 Multiply rounding to zero, clamp on overflow.
 
template<fixed_point Fxd>
constexpr Fxd abs (Fxd f) noexcept
 Same as fxd::abs(), clamp on overflow.
 

Detailed Description

Clamp on overflow.

Function Documentation

◆ abs()

constexpr Fxd abs ( Fxd  f)
constexprnoexcept

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

Definition at line 394 of file saturate.hpp.

◆ add()

constexpr Fxd add ( Fxd  a,
Fxd  b 
)
constexprnoexcept

Add, clamp on overflow.

Definition at line 275 of file saturate.hpp.

◆ assign()

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

Assignment, clamp on overflow.

Definition at line 196 of file saturate.hpp.

◆ fixed_cast() [1/2]

constexpr Dst fixed_cast ( Src  src)
constexprnoexcept

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

Definition at line 129 of file saturate.hpp.

◆ fixed_cast() [2/2]

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

Convenience overload.

Definition at line 143 of file saturate.hpp.

◆ from_raw()

constexpr Fxd from_raw ( val)
constexprnoexcept

Construct from raw value, clamp on overflow.

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

Definition at line 75 of file saturate.hpp.

◆ make_fixed() [1/2]

constexpr Dst make_fixed ( Src  src)
constexprnoexcept

Construct from numerical value, clamp on overflow.

Definition at line 88 of file saturate.hpp.

◆ make_fixed() [2/2]

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

Convenience overload.

Definition at line 115 of file saturate.hpp.

◆ make_ufixed()

constexpr Dst make_ufixed ( Src  src)
constexprnoexcept

Construct from numerical value, clamp on overflow (unsigned version).

Definition at line 101 of file saturate.hpp.

◆ negate()

constexpr Fxd negate ( Fxd  f)
constexprnoexcept

Negate, clamp on overflow.

Definition at line 263 of file saturate.hpp.

◆ post_dec()

constexpr Fxd post_dec ( Fxd &  f)
constexprnoexcept

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

Definition at line 249 of file saturate.hpp.

◆ post_inc()

constexpr Fxd post_inc ( Fxd &  f)
constexprnoexcept

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

Definition at line 222 of file saturate.hpp.

◆ pre_dec()

constexpr Fxd & pre_dec ( Fxd &  f)
constexprnoexcept

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

Definition at line 235 of file saturate.hpp.

◆ pre_inc()

constexpr Fxd & pre_inc ( Fxd &  f)
constexprnoexcept

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

Definition at line 208 of file saturate.hpp.

◆ saturate()

constexpr T saturate ( error  e)
constexprnoexcept

Error handler that clamps the value on error.

The returned value will always be clamped between std::numeric_limits<T>::lowest() and std::numeric_limits<T>::max() when it makes sense. The operation 0/0 will not return a value, it will raise the SIGFPE signal.

Definition at line 38 of file saturate.hpp.

◆ sub()

constexpr Fxd sub ( Fxd  a,
Fxd  b 
)
constexprnoexcept

Subtract, clamp on overflow.

Definition at line 288 of file saturate.hpp.

◆ to_int() [1/2]

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

Convert to the natural integer type, clamp on overflow.

Definition at line 184 of file saturate.hpp.

◆ to_int() [2/2]

constexpr I to_int ( Fxd  f)
constexprnoexcept

Convert to integer, clamp on overflow.

Definition at line 172 of file saturate.hpp.

◆ ufixed_cast()

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

Convenience overload (unsigned version).

Definition at line 158 of file saturate.hpp.