CppTools
Loading...
Searching...
No Matches
MathTools.hpp File Reference

Useful set of math functions. More...

#include <vector>
#include <cmath>

Go to the source code of this file.

Functions

template<typename T>
CppTools::MaximumFromCArray (const T *entries, const unsigned long n)
 Returns maximum value from C array.
template<typename... Ts>
double CppTools::Maximum (Ts... args)
 Returns maximum value from parameter pack.
template<typename T>
CppTools::MinimumFromCArray (const T *entries, const unsigned long n)
 Returns minimum value from C array.
template<typename... Ts>
double CppTools::Minimum (Ts... args)
 Returns minimum value from parameter pack.
template<typename T>
CppTools::AverageFromCArray (const T *entries, const unsigned long n)
 Returns average value from C array.
template<typename... Ts>
double CppTools::Average (Ts... args)
 Returns average value from parameter pack.
double CppTools::WeightedAverage (const double *entries, const double *weights, const unsigned long n)
 Returns average value from C arrays containing values and weights.
template<typename T>
double CppTools::StandardErrorFromCArray (const T *entries, const unsigned long n, const double average)
 Returns standard error value from C array.
template<typename... Ts>
double CppTools::StandardError (Ts... args)
 Returns average value from parameter pack.
template<typename T>
double CppTools::UncertaintyPropFromCArray (const T *entries, const unsigned long n)
 Returns uncertainty that is the propagated uncertainty from all uncertainties from C array.
template<typename... Ts>
double CppTools::UncertaintyProp (Ts... args)
 Returns uncertainty that is the propagated uncertainty from all uncertainties from parameter pack.
template<typename T>
CppTools::ProductFromCArray (const T *entries, const unsigned long n)
 Returns product of values from C array.
template<typename... Ts>
double CppTools::Product (Ts... args)
 Returns product of values from parameter pack.
template<typename T>
double CppTools::AtLeast1ProbFromCArray (const T *entries, const unsigned long n)
 Returns probability of at least 1 success from probabilities of different independent successes from C array.
template<typename... Ts>
double CppTools::AtLeast1Prob (Ts... args)
 Returns probability of at least 1 success from probabilities of different independent successes from parameter pack.
template<typename T>
double CppTools::RMSFromCArray (const T *entries, const unsigned long n)
 Returns root mean square (RMS) of values from C array.
template<typename... Ts>
double CppTools::RMS (Ts... args)
 Returns root mean square (RMS) of values from parameter pack.

Detailed Description

Useful set of math functions.

No library loading is required to use functions from this file since many of the functions in this file are template functions which do not support separate declaration.

This file is a part of a project CppTools (https://github.com/Sergeyir/CppTools).

Author
Sergei Antsupov (antsu.nosp@m.pov0.nosp@m.124@g.nosp@m.mail.nosp@m..com)

Function Documentation

◆ AtLeast1Prob()

template<typename... Ts>
double CppTools::AtLeast1Prob ( Ts... args)

Returns probability of at least 1 success from probabilities of different independent successes from parameter pack.

Parameters
[in]argsParameter pack
[out]resultProbability

◆ AtLeast1ProbFromCArray()

template<typename T>
double CppTools::AtLeast1ProbFromCArray ( const T * entries,
const unsigned long n )

Returns probability of at least 1 success from probabilities of different independent successes from C array.

Can be used with std::vector or std::array as such: AtLeast1ProbFromCArray(&some_vector[0], some_vector.size())

Parameters
[in]entriesarray
[in]nSize of array
[out]resultProbability

◆ Average()

template<typename... Ts>
double CppTools::Average ( Ts... args)

Returns average value from parameter pack.

Parameters
[in]argsParameter pack
[out]resultAverage value

◆ AverageFromCArray()

template<typename T>
T CppTools::AverageFromCArray ( const T * entries,
const unsigned long n )

Returns average value from C array.

Can be used with std::vector or std::array as such: AverageFromCArray(&some_vector[0], some_vector.size())

Parameters
[in]entriesarray
[in]nSize of array
[out]resultAverage value

◆ Maximum()

template<typename... Ts>
double CppTools::Maximum ( Ts... args)

Returns maximum value from parameter pack.

Parameters
[in]argsParameter pack
[out]resultMaximum value

◆ MaximumFromCArray()

template<typename T>
T CppTools::MaximumFromCArray ( const T * entries,
const unsigned long n )

Returns maximum value from C array.

Can be used with std::vector or std::array as such: MaximumFromCArray(&some_vector[0], some_vector.size())

Parameters
[in]entriesarray
[in]nSize of array
[out]resultMaximum value

◆ Minimum()

template<typename... Ts>
double CppTools::Minimum ( Ts... args)

Returns minimum value from parameter pack.

Parameters
[in]argsParameter pack
[out]resultMinimum value

◆ MinimumFromCArray()

template<typename T>
T CppTools::MinimumFromCArray ( const T * entries,
const unsigned long n )

Returns minimum value from C array.

Can be used with std::vector or std::array as such: MinimumArray(&some_vector[0], some_vector.size())

Parameters
[in]entriesarray
[in]nSize of array
[out]resultMinimum value

◆ Product()

template<typename... Ts>
double CppTools::Product ( Ts... args)

Returns product of values from parameter pack.

Parameters
[in]argsParameter pack
[out]resultProduct

◆ ProductFromCArray()

template<typename T>
T CppTools::ProductFromCArray ( const T * entries,
const unsigned long n )

Returns product of values from C array.

Can be used with std::vector or std::array as such: ProductFromCArray(&some_vector[0], some_vector.size())

Parameters
[in]entriesarray
[in]nSize of array
[out]resultProduct

◆ RMS()

template<typename... Ts>
double CppTools::RMS ( Ts... args)

Returns root mean square (RMS) of values from parameter pack.

Parameters
[in]argsParameter pack
[out]resultRMS

◆ RMSFromCArray()

template<typename T>
double CppTools::RMSFromCArray ( const T * entries,
const unsigned long n )

Returns root mean square (RMS) of values from C array.

Can be used with std::vector or std::array as such: RMSFromCarray(&some_vector[0], some_vector.size())

Parameters
[in]entriesarray
[in]nSize of array
[out]resultRMS

◆ StandardError()

template<typename... Ts>
double CppTools::StandardError ( Ts... args)

Returns average value from parameter pack.

Parameters
[in]argsParameter pack, last value in the pack must be the average value of the pack
[out]resultStandard error value

◆ StandardErrorFromCArray()

template<typename T>
double CppTools::StandardErrorFromCArray ( const T * entries,
const unsigned long n,
const double average )

Returns standard error value from C array.

Can be used with std::vector or std::array as such: StandardErrorFromCArray(&some_vector[0], some_vector.size())

Parameters
[in]entriesarray
[in]nSize of array
[out]resultStandard error value

◆ UncertaintyProp()

template<typename... Ts>
double CppTools::UncertaintyProp ( Ts... args)

Returns uncertainty that is the propagated uncertainty from all uncertainties from parameter pack.

Uncertainties are relative.

Parameters
[in]argsParameter pack
[out]resultPropagated uncertainty

◆ UncertaintyPropFromCArray()

template<typename T>
double CppTools::UncertaintyPropFromCArray ( const T * entries,
const unsigned long n )

Returns uncertainty that is the propagated uncertainty from all uncertainties from C array.

Uncertainties are relative. Can be used with std::vector or std::array as such: StandardErrorFromCArray(&some_vector[0], some_vector.size())

Parameters
[in]entriesarray (contains uncertainties)
[in]nSize of array
[out]resultPropagated uncertainty

◆ WeightedAverage()

double CppTools::WeightedAverage ( const double * entries,
const double * weights,
const unsigned long n )

Returns average value from C arrays containing values and weights.

Can be used with std::vector or std::array as such: WeightedAverage(&some_vector[0], some_vector.size())

Parameters
[in]entriesarray with values
[in]weightsarray with weights
[in]nSize of array
[out]resultWeighted average value