faunus
Public Member Functions | List of all members
Faunus::Quantize< Tfloat > Class Template Reference

Round and bin numbers for use with tables and histograms. More...

#include <auxiliary.h>

Public Member Functions

 Quantize (Tfloat dx, Tfloat xmin=0)
 Constructor. More...
 
Quantizeoperator= (Tfloat val)
 Assigment operator.
 
Quantizefrombin (unsigned int i)
 
Quantizeoperator() (Tfloat val)
 Assignment with function operator.
 
template<typename T >
 operator T ()
 Implicit convertion to integral (bin) or float (rounded)
 

Detailed Description

template<std::floating_point Tfloat = double>
class Faunus::Quantize< Tfloat >

Round and bin numbers for use with tables and histograms.

This will round a float to nearest value divisible by dx or convert to an integer corresponding to a binning value. In the latter case, a minimum value must be specified upon construction.

Example:

Quantize<double> Q(0.5, -0.5);
Q = 0.61;
double x = Q; // --> 0.5
int bin = Q; // --> 2
bin = Q(-0.5); // --> 0
x = Q.frombin(2); // --> 0.5
std::vector<bool> v(10);
v[ Q(0.61) ] = false; // 2nd element set to false

Constructor & Destructor Documentation

◆ Quantize()

template<std::floating_point Tfloat = double>
Faunus::Quantize< Tfloat >::Quantize ( Tfloat  dx,
Tfloat  xmin = 0 
)
inline

Constructor.

Parameters
dxresolution
xminminimum value if converting to integral type (binning)

The documentation for this class was generated from the following file: