Lumiera
0.pre.03
»edit your freedom«
|
Go to the source code of this file.
Utilities for quantisation (grid alignment) and comparisons.
Definition in file util-quant.hpp.
#include <cstdlib>
#include <climits>
#include <cfloat>
#include <cmath>
Classes | |
struct | IDiv< I > |
helper to treat int or long division uniformly More... | |
struct | IDiv< int > |
struct | IDiv< llong > |
struct | IDiv< long > |
Functions | |
bool | almostEqual (double d1, double d2, unsigned int ulp=2) |
epsilon comparison of doubles. More... | |
template<typename I > | |
I | floordiv (I num, I den) |
floor function for integer arithmetics. More... | |
template<typename I > | |
IDiv< I > | floorwrap (I num, I den) |
scale wrapping operation. More... | |
template<typename I > | |
IDiv< I > | iDiv (I num, I den) |
template<typename I > | |
constexpr int | ilog2 (I num) |
Integral binary logarithm (disregarding fractional part) More... | |
template<typename N > | |
bool constexpr | isPow2 (N n) |
|
inline |
den | support type inference and auto typing... |
Definition at line 82 of file util-quant.hpp.
References util::iDiv().
Referenced by util::iDiv(), and util::reQuant().
|
inline |
floor function for integer arithmetics.
Unlike the built-in integer division, this function always rounds towards the next smaller integer, even for negative numbers.
Definition at line 97 of file util-quant.hpp.
References util::floordiv().
Referenced by util::floordiv().
|
inline |
scale wrapping operation.
Quantises the numerator value into the scale given by the denominator. Unlike the built-in integer division, this function always rounds towards the next smaller integer and also relates the remainder (=modulo) to this next lower scale grid point.
Definition at line 119 of file util-quant.hpp.
References util::floorwrap().
Referenced by util::floorwrap().
|
inline |
epsilon comparison of doubles.
ulp | number of grid steps to allow for difference (default = 2). Here, a 'grid step' is the smallest difference to 1.0 which can be represented in floating point ('units in the last place') |
Definition at line 150 of file util-quant.hpp.
References util::almostEqual().
Referenced by util::almostEqual().
|
inline |
Integral binary logarithm (disregarding fractional part)
num
; -1 for num==0
std::bit_width(i)
— run a microbenchmark! std::ilogb(double)
perform in the same order of magnitude (which is surprising). This function gets slightly faster for smaller data types. The naive bitshift-count implementation is always significantly slower (8 times for int64_t, 1.6 times for int8_t) Definition at line 178 of file util-quant.hpp.
References util::ilog2().
Referenced by util::ilog2(), and Rational_test::verify_intLog2().