tlx
Loading...
Searching...
No Matches

Simple math functions. More...

Classes

class  Aggregate< Type_ >
 Calculate running aggregate statistics: feed it with values, and it will keep the minimum, the maximum, the average, the value number, and the standard deviation is values. More...
 
class  AggregateMinMax< Type_ >
 Calculate running aggregate statistics: feed it with values, and it will keep the minimum and the maximum values. More...
 
class  PolynomialRegression< Type, WithStore >
 Calculate the regression polynomial \( a_0+a_1x^1+a_2x^2+\cdots+a_nx^n \) from a list of 2D points. More...
 

Functions

template<typename T >
abs_diff (const T &a, const T &b)
 absolute difference, which also works for unsigned types
 
static uint16_t bswap16_generic (const uint16_t &x)
 bswap16 - generic implementation
 
static uint16_t bswap16 (const uint16_t &v)
 bswap16 - generic
 
static uint32_t bswap32_generic (const uint32_t &x)
 bswap32 - generic implementation
 
static uint32_t bswap32 (const uint32_t &v)
 bswap32 - generic
 
static uint64_t bswap64_generic (const uint64_t &x)
 bswap64 - generic implementation
 
static uint64_t bswap64 (const uint64_t &v)
 bswap64 - generic
 
template<typename Integral >
static unsigned clz_template (Integral x)
 clz (count leading zeros) - generic implementation
 
template<typename Integral >
unsigned clz (Integral x)
 
template<>
unsigned clz< int > (int i)
 clz (count leading zeros)
 
template<>
unsigned clz< unsigned > (unsigned i)
 clz (count leading zeros)
 
template<>
unsigned clz< long > (long i)
 clz (count leading zeros)
 
template<>
unsigned clz< unsigned long > (unsigned long i)
 clz (count leading zeros)
 
template<>
unsigned clz< long long > (long long i)
 clz (count leading zeros)
 
template<>
unsigned clz< unsigned long long > (unsigned long long i)
 clz (count leading zeros)
 
template<typename Integral >
static unsigned ctz_template (Integral x)
 ctz (count trailing zeros) - generic implementation
 
template<typename Integral >
unsigned ctz (Integral x)
 
template<>
unsigned ctz< int > (int i)
 ctz (count trailing zeros)
 
template<>
unsigned ctz< unsigned > (unsigned i)
 ctz (count trailing zeros)
 
template<>
unsigned ctz< long > (long i)
 ctz (count trailing zeros)
 
template<>
unsigned ctz< unsigned long > (unsigned long i)
 ctz (count trailing zeros)
 
template<>
unsigned ctz< long long > (long long i)
 ctz (count trailing zeros)
 
template<>
unsigned ctz< unsigned long long > (unsigned long long i)
 ctz (count trailing zeros)
 
template<typename IntegralN , typename IntegralK >
static constexpr auto div_ceil (const IntegralN &n, const IntegralK &k) -> decltype(n+k)
 calculate n div k with rounding up, for n and k positive!
 
template<typename Integral >
static unsigned ffs_template (Integral x)
 ffs (find first set bit) - generic implementation
 
static unsigned ffs (int i)
 find first set bit in integer, or zero if none are set.
 
static unsigned ffs (unsigned int i)
 find first set bit in integer, or zero if none are set.
 
static unsigned ffs (long i)
 find first set bit in integer, or zero if none are set.
 
static unsigned ffs (unsigned long i)
 find first set bit in integer, or zero if none are set.
 
static unsigned ffs (long long i)
 find first set bit in integer, or zero if none are set.
 
static unsigned ffs (unsigned long long i)
 find first set bit in integer, or zero if none are set.
 
template<typename IntegerType >
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor_template (IntegerType i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor (int i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor (unsigned int i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor (long i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor (unsigned long i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor (long long i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor (unsigned long long i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil (int i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil (unsigned int i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil (long i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil (unsigned long i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil (long long i)
 calculate the log2 floor of an integer type
 
static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil (unsigned long long i)
 calculate the log2 floor of an integer type
 
template<typename Integral >
static bool is_power_of_two_template (Integral i)
 
static bool is_power_of_two (int i)
 does what it says: true if i is a power of two
 
static bool is_power_of_two (unsigned int i)
 does what it says: true if i is a power of two
 
static bool is_power_of_two (long i)
 does what it says: true if i is a power of two
 
static bool is_power_of_two (unsigned long i)
 does what it says: true if i is a power of two
 
static bool is_power_of_two (long long i)
 does what it says: true if i is a power of two
 
static bool is_power_of_two (unsigned long long i)
 does what it says: true if i is a power of two
 
static unsigned popcount_generic8 (uint8_t x)
 popcount (count one bits) - generic SWAR implementation
 
static unsigned popcount_generic16 (uint16_t x)
 popcount (count one bits) - generic SWAR implementation
 
static unsigned popcount_generic32 (uint32_t x)
 popcount (count one bits) - generic SWAR implementation from https://stackoverflow.com/questions/109023
 
static unsigned popcount_generic64 (uint64_t x)
 popcount (count one bits) - generic SWAR implementation
 
template<typename Integral >
unsigned popcount (Integral i)
 popcount (count one bits)
 
static size_t popcount (const void *data, size_t size)
 
template<unsigned D, typename T >
static constexpr T power_to_the (T x)
 power_to_the<D>(x)
 
static uint32_t rol32_generic (const uint32_t &x, int i)
 rol32 - generic implementation
 
static uint32_t rol32 (const uint32_t &x, int i)
 rol32 - generic
 
static uint64_t rol64_generic (const uint64_t &x, int i)
 rol64 - generic implementation
 
static uint64_t rol64 (const uint64_t &x, int i)
 rol64 - generic
 
static uint32_t ror32_generic (const uint32_t &x, int i)
 ror32 - generic implementation
 
static uint32_t ror32 (const uint32_t &x, int i)
 ror32 - generic
 
static uint64_t ror64_generic (const uint64_t &x, int i)
 ror64 - generic implementation
 
static uint64_t ror64 (const uint64_t &x, int i)
 ror64 - generic
 
template<typename Integral >
static Integral round_up_to_power_of_two_template (Integral n)
 
static int round_up_to_power_of_two (int i)
 does what it says: round up to next power of two
 
static unsigned int round_up_to_power_of_two (unsigned int i)
 does what it says: round up to next power of two
 
static long round_up_to_power_of_two (long i)
 does what it says: round up to next power of two
 
static unsigned long round_up_to_power_of_two (unsigned long i)
 does what it says: round up to next power of two
 
static long long round_up_to_power_of_two (long long i)
 does what it says: round up to next power of two
 
static unsigned long long round_up_to_power_of_two (unsigned long long i)
 does what it says: round up to next power of two
 
static int round_down_to_power_of_two (int i)
 does what it says: round down to next power of two
 
static unsigned int round_down_to_power_of_two (unsigned int i)
 does what it says: round down to next power of two
 
static long round_down_to_power_of_two (long i)
 does what it says: round down to next power of two
 
static unsigned long round_down_to_power_of_two (unsigned long i)
 does what it says: round down to next power of two
 
static long long round_down_to_power_of_two (long long i)
 does what it says: round down to next power of two
 
static unsigned long long round_down_to_power_of_two (unsigned long long i)
 does what it says: round down to next power of two
 
template<typename IntegralN , typename IntegralK >
static constexpr auto round_up (const IntegralN &n, const IntegralK &k) -> decltype(n+k)
 round n up to the next multiple of k, for n and k positive!
 
template<typename T >
int sgn (const T &val)
 sgn() - signum
 

Detailed Description

Simple math functions.

Function Documentation

◆ abs_diff()

T abs_diff ( const T &  a,
const T &  b 
)

absolute difference, which also works for unsigned types

Definition at line 24 of file abs_diff.hpp.

◆ bswap16()

static uint16_t bswap16 ( const uint16_t &  v)
inlinestatic

bswap16 - generic

Definition at line 52 of file bswap.hpp.

◆ bswap16_generic()

static uint16_t bswap16_generic ( const uint16_t &  x)
inlinestatic

bswap16 - generic implementation

Definition at line 31 of file bswap.hpp.

◆ bswap32()

static uint32_t bswap32 ( const uint32_t &  v)
inlinestatic

bswap32 - generic

Definition at line 84 of file bswap.hpp.

◆ bswap32_generic()

static uint32_t bswap32_generic ( const uint32_t &  x)
inlinestatic

bswap32 - generic implementation

Definition at line 62 of file bswap.hpp.

◆ bswap64()

static uint64_t bswap64 ( const uint64_t &  v)
inlinestatic

bswap64 - generic

Definition at line 122 of file bswap.hpp.

◆ bswap64_generic()

static uint64_t bswap64_generic ( const uint64_t &  x)
inlinestatic

bswap64 - generic implementation

Definition at line 94 of file bswap.hpp.

◆ clz()

unsigned clz ( Integral  x)
inline

◆ clz< int >()

unsigned clz< int > ( int  i)
inline

clz (count leading zeros)

Definition at line 112 of file clz.hpp.

◆ clz< long >()

unsigned clz< long > ( long  i)
inline

clz (count leading zeros)

Definition at line 124 of file clz.hpp.

◆ clz< long long >()

unsigned clz< long long > ( long long  i)
inline

clz (count leading zeros)

Definition at line 136 of file clz.hpp.

◆ clz< unsigned >()

unsigned clz< unsigned > ( unsigned  i)
inline

clz (count leading zeros)

Definition at line 118 of file clz.hpp.

◆ clz< unsigned long >()

unsigned clz< unsigned long > ( unsigned long  i)
inline

clz (count leading zeros)

Definition at line 130 of file clz.hpp.

◆ clz< unsigned long long >()

unsigned clz< unsigned long long > ( unsigned long long  i)
inline

clz (count leading zeros)

Definition at line 142 of file clz.hpp.

◆ clz_template()

static unsigned clz_template ( Integral  x)
inlinestatic

clz (count leading zeros) - generic implementation

Definition at line 30 of file clz.hpp.

◆ ctz()

unsigned ctz ( Integral  x)
inline

◆ ctz< int >()

unsigned ctz< int > ( int  i)
inline

ctz (count trailing zeros)

Definition at line 112 of file ctz.hpp.

◆ ctz< long >()

unsigned ctz< long > ( long  i)
inline

ctz (count trailing zeros)

Definition at line 124 of file ctz.hpp.

◆ ctz< long long >()

unsigned ctz< long long > ( long long  i)
inline

ctz (count trailing zeros)

Definition at line 136 of file ctz.hpp.

◆ ctz< unsigned >()

unsigned ctz< unsigned > ( unsigned  i)
inline

ctz (count trailing zeros)

Definition at line 118 of file ctz.hpp.

◆ ctz< unsigned long >()

unsigned ctz< unsigned long > ( unsigned long  i)
inline

ctz (count trailing zeros)

Definition at line 130 of file ctz.hpp.

◆ ctz< unsigned long long >()

unsigned ctz< unsigned long long > ( unsigned long long  i)
inline

ctz (count trailing zeros)

Definition at line 142 of file ctz.hpp.

◆ ctz_template()

static unsigned ctz_template ( Integral  x)
inlinestatic

ctz (count trailing zeros) - generic implementation

Definition at line 30 of file ctz.hpp.

◆ div_ceil()

static constexpr auto div_ceil ( const IntegralN &  n,
const IntegralK &  k 
) -> decltype(n + k)
inlinestaticconstexpr

calculate n div k with rounding up, for n and k positive!

Definition at line 25 of file div_ceil.hpp.

◆ ffs() [1/6]

static unsigned ffs ( int  i)
inlinestatic

find first set bit in integer, or zero if none are set.

Definition at line 79 of file ffs.hpp.

◆ ffs() [2/6]

static unsigned ffs ( long  i)
inlinestatic

find first set bit in integer, or zero if none are set.

Definition at line 91 of file ffs.hpp.

◆ ffs() [3/6]

static unsigned ffs ( long long  i)
inlinestatic

find first set bit in integer, or zero if none are set.

Definition at line 103 of file ffs.hpp.

◆ ffs() [4/6]

static unsigned ffs ( unsigned int  i)
inlinestatic

find first set bit in integer, or zero if none are set.

Definition at line 85 of file ffs.hpp.

◆ ffs() [5/6]

static unsigned ffs ( unsigned long  i)
inlinestatic

find first set bit in integer, or zero if none are set.

Definition at line 97 of file ffs.hpp.

◆ ffs() [6/6]

static unsigned ffs ( unsigned long long  i)
inlinestatic

find first set bit in integer, or zero if none are set.

Definition at line 109 of file ffs.hpp.

◆ ffs_template()

static unsigned ffs_template ( Integral  x)
inlinestatic

ffs (find first set bit) - generic implementation

Definition at line 27 of file ffs.hpp.

◆ integer_log2_ceil() [1/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil ( int  i)
static

calculate the log2 floor of an integer type

Definition at line 113 of file integer_log2.hpp.

◆ integer_log2_ceil() [2/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil ( long  i)
static

calculate the log2 floor of an integer type

Definition at line 125 of file integer_log2.hpp.

◆ integer_log2_ceil() [3/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil ( long long  i)
static

calculate the log2 floor of an integer type

Definition at line 137 of file integer_log2.hpp.

◆ integer_log2_ceil() [4/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil ( unsigned int  i)
static

calculate the log2 floor of an integer type

Definition at line 119 of file integer_log2.hpp.

◆ integer_log2_ceil() [5/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil ( unsigned long  i)
static

calculate the log2 floor of an integer type

Definition at line 131 of file integer_log2.hpp.

◆ integer_log2_ceil() [6/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_ceil ( unsigned long long  i)
static

calculate the log2 floor of an integer type

Definition at line 143 of file integer_log2.hpp.

◆ integer_log2_floor() [1/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor ( int  i)
static

calculate the log2 floor of an integer type

Definition at line 78 of file integer_log2.hpp.

◆ integer_log2_floor() [2/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor ( long  i)
static

calculate the log2 floor of an integer type

Definition at line 88 of file integer_log2.hpp.

◆ integer_log2_floor() [3/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor ( long long  i)
static

calculate the log2 floor of an integer type

Definition at line 98 of file integer_log2.hpp.

◆ integer_log2_floor() [4/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor ( unsigned int  i)
static

calculate the log2 floor of an integer type

Definition at line 83 of file integer_log2.hpp.

◆ integer_log2_floor() [5/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor ( unsigned long  i)
static

calculate the log2 floor of an integer type

Definition at line 93 of file integer_log2.hpp.

◆ integer_log2_floor() [6/6]

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor ( unsigned long long  i)
static

calculate the log2 floor of an integer type

Definition at line 103 of file integer_log2.hpp.

◆ integer_log2_floor_template()

static TLX_ADVANCED_CONSTEXPR unsigned integer_log2_floor_template ( IntegerType  i)
static

calculate the log2 floor of an integer type

Definition at line 26 of file integer_log2.hpp.

◆ is_power_of_two() [1/6]

static bool is_power_of_two ( int  i)
inlinestatic

does what it says: true if i is a power of two

Definition at line 31 of file is_power_of_two.hpp.

◆ is_power_of_two() [2/6]

static bool is_power_of_two ( long  i)
inlinestatic

does what it says: true if i is a power of two

Definition at line 41 of file is_power_of_two.hpp.

◆ is_power_of_two() [3/6]

static bool is_power_of_two ( long long  i)
inlinestatic

does what it says: true if i is a power of two

Definition at line 51 of file is_power_of_two.hpp.

◆ is_power_of_two() [4/6]

static bool is_power_of_two ( unsigned int  i)
inlinestatic

does what it says: true if i is a power of two

Definition at line 36 of file is_power_of_two.hpp.

◆ is_power_of_two() [5/6]

static bool is_power_of_two ( unsigned long  i)
inlinestatic

does what it says: true if i is a power of two

Definition at line 46 of file is_power_of_two.hpp.

◆ is_power_of_two() [6/6]

static bool is_power_of_two ( unsigned long long  i)
inlinestatic

does what it says: true if i is a power of two

Definition at line 56 of file is_power_of_two.hpp.

◆ is_power_of_two_template()

static bool is_power_of_two_template ( Integral  i)
inlinestatic

Definition at line 22 of file is_power_of_two.hpp.

◆ popcount() [1/2]

static size_t popcount ( const void *  data,
size_t  size 
)
inlinestatic

Definition at line 133 of file popcount.hpp.

◆ popcount() [2/2]

unsigned popcount ( Integral  i)
inline

popcount (count one bits)

Definition at line 114 of file popcount.hpp.

◆ popcount_generic16()

static unsigned popcount_generic16 ( uint16_t  x)
inlinestatic

popcount (count one bits) - generic SWAR implementation

Definition at line 39 of file popcount.hpp.

◆ popcount_generic32()

static unsigned popcount_generic32 ( uint32_t  x)
inlinestatic

popcount (count one bits) - generic SWAR implementation from https://stackoverflow.com/questions/109023

Definition at line 47 of file popcount.hpp.

◆ popcount_generic64()

static unsigned popcount_generic64 ( uint64_t  x)
inlinestatic

popcount (count one bits) - generic SWAR implementation

Definition at line 54 of file popcount.hpp.

◆ popcount_generic8()

static unsigned popcount_generic8 ( uint8_t  x)
inlinestatic

popcount (count one bits) - generic SWAR implementation

Definition at line 32 of file popcount.hpp.

◆ power_to_the()

static constexpr T power_to_the ( x)
inlinestaticconstexpr

power_to_the<D>(x)

returns x raised to the power of D using log(D) explicit multiplications.

Definition at line 30 of file power_to_the.hpp.

◆ rol32()

static uint32_t rol32 ( const uint32_t &  x,
int  i 
)
inlinestatic

rol32 - generic

Definition at line 55 of file rol.hpp.

◆ rol32_generic()

static uint32_t rol32_generic ( const uint32_t &  x,
int  i 
)
inlinestatic

rol32 - generic implementation

Definition at line 31 of file rol.hpp.

◆ rol64()

static uint64_t rol64 ( const uint64_t &  x,
int  i 
)
inlinestatic

rol64 - generic

Definition at line 89 of file rol.hpp.

◆ rol64_generic()

static uint64_t rol64_generic ( const uint64_t &  x,
int  i 
)
inlinestatic

rol64 - generic implementation

Definition at line 65 of file rol.hpp.

◆ ror32()

static uint32_t ror32 ( const uint32_t &  x,
int  i 
)
inlinestatic

ror32 - generic

Definition at line 55 of file ror.hpp.

◆ ror32_generic()

static uint32_t ror32_generic ( const uint32_t &  x,
int  i 
)
inlinestatic

ror32 - generic implementation

Definition at line 31 of file ror.hpp.

◆ ror64()

static uint64_t ror64 ( const uint64_t &  x,
int  i 
)
inlinestatic

ror64 - generic

Definition at line 89 of file ror.hpp.

◆ ror64_generic()

static uint64_t ror64_generic ( const uint64_t &  x,
int  i 
)
inlinestatic

ror64 - generic implementation

Definition at line 65 of file ror.hpp.

◆ round_down_to_power_of_two() [1/6]

static int round_down_to_power_of_two ( int  i)
inlinestatic

does what it says: round down to next power of two

Definition at line 72 of file round_to_power_of_two.hpp.

◆ round_down_to_power_of_two() [2/6]

static long round_down_to_power_of_two ( long  i)
inlinestatic

does what it says: round down to next power of two

Definition at line 82 of file round_to_power_of_two.hpp.

◆ round_down_to_power_of_two() [3/6]

static long long round_down_to_power_of_two ( long long  i)
inlinestatic

does what it says: round down to next power of two

Definition at line 92 of file round_to_power_of_two.hpp.

◆ round_down_to_power_of_two() [4/6]

static unsigned int round_down_to_power_of_two ( unsigned int  i)
inlinestatic

does what it says: round down to next power of two

Definition at line 77 of file round_to_power_of_two.hpp.

◆ round_down_to_power_of_two() [5/6]

static unsigned long round_down_to_power_of_two ( unsigned long  i)
inlinestatic

does what it says: round down to next power of two

Definition at line 87 of file round_to_power_of_two.hpp.

◆ round_down_to_power_of_two() [6/6]

static unsigned long long round_down_to_power_of_two ( unsigned long long  i)
inlinestatic

does what it says: round down to next power of two

Definition at line 98 of file round_to_power_of_two.hpp.

◆ round_up()

static constexpr auto round_up ( const IntegralN &  n,
const IntegralK &  k 
) -> decltype(n + k)
inlinestaticconstexpr

round n up to the next multiple of k, for n and k positive!

Definition at line 25 of file round_up.hpp.

◆ round_up_to_power_of_two() [1/6]

static int round_up_to_power_of_two ( int  i)
inlinestatic

does what it says: round up to next power of two

Definition at line 38 of file round_to_power_of_two.hpp.

◆ round_up_to_power_of_two() [2/6]

static long round_up_to_power_of_two ( long  i)
inlinestatic

does what it says: round up to next power of two

Definition at line 48 of file round_to_power_of_two.hpp.

◆ round_up_to_power_of_two() [3/6]

static long long round_up_to_power_of_two ( long long  i)
inlinestatic

does what it says: round up to next power of two

Definition at line 58 of file round_to_power_of_two.hpp.

◆ round_up_to_power_of_two() [4/6]

static unsigned int round_up_to_power_of_two ( unsigned int  i)
inlinestatic

does what it says: round up to next power of two

Definition at line 43 of file round_to_power_of_two.hpp.

◆ round_up_to_power_of_two() [5/6]

static unsigned long round_up_to_power_of_two ( unsigned long  i)
inlinestatic

does what it says: round up to next power of two

Definition at line 53 of file round_to_power_of_two.hpp.

◆ round_up_to_power_of_two() [6/6]

static unsigned long long round_up_to_power_of_two ( unsigned long long  i)
inlinestatic

does what it says: round up to next power of two

Definition at line 64 of file round_to_power_of_two.hpp.

◆ round_up_to_power_of_two_template()

static Integral round_up_to_power_of_two_template ( Integral  n)
inlinestatic

Definition at line 25 of file round_to_power_of_two.hpp.

◆ sgn()

int sgn ( const T &  val)

sgn() - signum

return the signum (-1, 0, +1) of a value.

Definition at line 26 of file sgn.hpp.