cxxomfort  rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
Classes
cxxomfort::st_math Namespace Reference

Namespace for compile-time static (template based) arithmetic operations. More...

Classes

struct  midpoint
 Defines the member value , with value of type Int that is the numeric value at the middle between a and b. More...
 
struct  static_abs
 Provides the member value with one of the values [-u, 0, +u] depending on the sign of u . More...
 
struct  static_abs_s
 Absolute value of a intmax_t . More...
 
struct  static_abs_u
 Absolute value of a uintmax_t . More...
 
struct  static_clamp
 Defines the member value which is t, constrained to the range [m,M]. More...
 
struct  static_intlog
 Provides the member value with the value of the logarithm of N in base Ba . More...
 
struct  static_intpow
 Defines the member value , of type Int and of value equal to x to the power of y . More...
 
struct  static_minmax2
 Defines the member values Tmin , Tmax with the minimum or maximum value between t0 and t1 . More...
 
struct  static_sign
 Provides the member value with the sign of template parameter T u . More...
 
struct  static_sign_s
 Sign of a intmax_t . More...
 
struct  static_sign_u
 Sign of a uintmax_t . More...
 

Detailed Description

Namespace for compile-time static (template based) arithmetic operations.


Class Documentation

◆ cxxomfort::st_math::static_sign

struct cxxomfort::st_math::static_sign

template<typename T, T u>
struct cxxomfort::st_math::static_sign< T, u >

Provides the member value with the sign of template parameter T u .

Template Parameters
uA compile-time value of type T used as argument.
Utilities:
Compile-time sign of an integer

The helper types static_sign_s and statuc_sign_u omit the parameter types and operate on intmax_t and uintmax_t values, respectively.

int sign_neg_999 = st_math::static_sign<short,-999>::value;
int sign_1 = st_math::static_sign_s<148000000>::value;
int sign_2 = st_math::static_sign_u<148000000>::value;

See also static_abs .