Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
CsMath Namespace Reference

Classes

class  Interval
 Represents an interval by two unsigned integers [base, base + diff]. More...
 

Functions

template<class T , class U >
constexpr T SafeAdd (T lhs, U rhs)
 returns lhs+rhs, clamping return values that would roll over to the min/max values of lhs. More...
 
template<class T , class U = int>
constexpr T & Increase (T &obj, U diff=1)
 roll over safe variant of ++some_value; More...
 
template<class T , class U = int>
constexpr T & Decrease (T &obj, U diff=1)
 roll over safe variant of –some_value; More...
 
template<class T , class M , class U = int>
constexpr decltype(auto) DecreaseMember (T &obj, M member, U diff=1)
 Identical to the other decrease function. More...
 
template<class T , class S >
auto mod (T v, S m) -> decltype(v % m)
 Returns the canonical representation of [v] considered as element of Z/mZ, regardless of any silly features C++ board thought that would be better than actual math when using non-positive input. More...
 
template<class T , class S >
auto min (T l, S r)
 
template<class T , class S >
auto max (T l, S r)
 
template<class V , class L , class U >
auto clamp (V value, L lower, U upper)
 Returns: More...
 
template<class T >
round (float val)
 Rounds a numeric value. More...
 

Function Documentation

◆ clamp()

template<class V , class L , class U >
auto CsMath::clamp ( value,
lower,
upper 
)

Returns:

  • lower if value <= lower
  • upper if value >= upper
  • value else.

◆ Decrease()

template<class T , class U = int>
constexpr T & CsMath::Decrease ( T &  obj,
diff = 1 
)
inlineconstexpr

roll over safe variant of –some_value;

◆ DecreaseMember()

template<class T , class M , class U = int>
constexpr decltype(auto) CsMath::DecreaseMember ( T &  obj,
member,
diff = 1 
)
inlineconstexpr

Identical to the other decrease function.

Use this variation if you get errors like: 'cannot bind packed field to ...&' or 'taking address of packed member ... may result in an unaligned pointer value'.

◆ Increase()

template<class T , class U = int>
constexpr T & CsMath::Increase ( T &  obj,
diff = 1 
)
inlineconstexpr

roll over safe variant of ++some_value;

◆ max()

template<class T , class S >
auto CsMath::max ( l,
r 
)

◆ min()

template<class T , class S >
auto CsMath::min ( l,
r 
)

◆ mod()

template<class T , class S >
auto CsMath::mod ( v,
m 
) -> decltype(v % m)

Returns the canonical representation of [v] considered as element of Z/mZ, regardless of any silly features C++ board thought that would be better than actual math when using non-positive input.

Return value is always in the half open interval [0,m). For any values v,n and m, mod(v,m) == mod(v+ n*m, m) holds.

Template implemented for integral types.

◆ round()

template<class T >
T CsMath::round ( float  val)

Rounds a numeric value.

◆ SafeAdd()

template<class T , class U >
constexpr T CsMath::SafeAdd ( lhs,
rhs 
)
inlineconstexpr

returns lhs+rhs, clamping return values that would roll over to the min/max values of lhs.