yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.9.0
MathUtils.h File Reference
#include "YODA/Config/BuildConfig.h"
#include <stdexcept>
#include <string>
#include <ostream>
#include <sstream>
#include <iostream>
#include <cmath>
#include <map>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cassert>
#include <limits>
#include <climits>
#include <cfloat>

Go to the source code of this file.

Namespaces

 YODA
 

Enumerations

enum  YODA::Sign { YODA::MINUS = -1, YODA::ZERO = 0, YODA::PLUS = 1 }
 Enum for signs of numbers. More...
 

Functions

Comparison functions for safe floating point equality tests
bool YODA::isZero (double val, double tolerance=1E-8)
 
bool YODA::isZero (long val, double=1E-8)
 
bool YODA::fuzzyEquals (double a, double b, double tolerance=1E-5)
 Compare two floating point numbers for equality with a degree of fuzziness. More...
 
bool YODA::fuzzyEquals (long a, long b, double=1E-5)
 Compare two integral-type numbers for equality with a degree of fuzziness. More...
 
bool YODA::fuzzyGtrEquals (double a, double b, double tolerance=1E-5)
 Compare two floating point numbers for >= with a degree of fuzziness. More...
 
bool YODA::fuzzyGtrEquals (long a, long b, double=1E-5)
 Compare two integral-type numbers for >= with a degree of fuzziness. More...
 
bool YODA::fuzzyLessEquals (double a, double b, double tolerance=1E-5)
 Compare two floating point numbers for <= with a degree of fuzziness. More...
 
bool YODA::fuzzyLessEquals (long a, long b, double=1E-5)
 Compare two integral-type numbers for <= with a degree of fuzziness. More...
 
double YODA::approx (double a, int n=5)
 Returns a number floored at the nth decimal place. More...
 
Miscellaneous numerical helpers
template<typename NUM >
NUM YODA::sqr (NUM a)
 Named number-type squaring operation. More...
 
template<typename Num >
Num YODA::add_quad (Num a, Num b)
 Named number-type addition in quadrature operation. More...
 
template<typename Num >
Num YODA::add_quad (Num a, Num b, Num c)
 Named number-type addition in quadrature operation. More...
 
int YODA::sign (double val)
 Find the sign of a number. More...
 
int YODA::sign (int val)
 Find the sign of a number. More...
 
int YODA::sign (long val)
 Find the sign of a number. More...
 
Binning helper functions
std::vector< double > YODA::linspace (size_t nbins, double xmin, double xmax, bool include_end=true)
 Make a list of nbins + 1 values uniformly spaced between xmin and xmax inclusive. More...
 
std::vector< double > YODA::logspace (size_t nbins, double xmin, double xmax, bool include_end=true)
 Make a list of nbins + 1 values uniformly spaced in log(x) between xmin and xmax inclusive. More...
 
std::vector< double > YODA::pdfspace (size_t nbins, double xmin, double xmax, std::function< double(double)> &fn, size_t nsample=10000)
 Make a list of nbins + 1 values spaced with density ~ f(x) between xmin and end inclusive. More...
 
template<typename NUM >
int YODA::index_between (const NUM &val, const std::vector< NUM > &binedges)
 Return the bin index of the given value, val, given a vector of bin edges. More...
 
Statistics functions
double YODA::mean (const std::vector< int > &sample)
 Calculate the mean of a sample. More...
 
double YODA::covariance (const std::vector< int > &sample1, const std::vector< int > &sample2)
 Calculate the covariance (variance) between two samples. More...
 
double YODA::correlation (const std::vector< int > &sample1, const std::vector< int > &sample2)
 Calculate the correlation strength between two samples. More...
 

Variables

static const double YODA::MAXDOUBLE = DBL_MAX
 
static const double YODA::MAXINT = INT_MAX
 
static const double YODA::PI = M_PI
 A pre-defined value of $ \pi $. More...
 
static const double YODA::TWOPI = 2*M_PI
 A pre-defined value of $ 2\pi $. More...
 
static const double YODA::HALFPI = M_PI_2
 A pre-defined value of $ \pi/2 $. More...
 

Ranges and intervals

enum  YODA::RangeBoundary { YODA::OPEN =0, YODA::SOFT =0, YODA::CLOSED =1, YODA::HARD =1 }
 
template<typename NUM >
bool YODA::inRange (NUM value, NUM low, NUM high, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Determine if value is in the range low to high, for floating point numbers. More...
 
template<typename NUM >
bool YODA::inRange (NUM value, std::pair< NUM, NUM > lowhigh, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Alternative version of inRange for doubles, which accepts a pair for the range arguments. More...
 
bool YODA::inRange (int value, int low, int high, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=CLOSED)
 Determine if value is in the range low to high, for integer types. More...
 
bool YODA::inRange (int value, std::pair< int, int > lowhigh, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Alternative version of inRange for ints, which accepts a pair for the range arguments. More...