35 #ifndef OPENMS_MATH_MISC_MATHFUNCTIONS_H 36 #define OPENMS_MATH_MISC_MATHFUNCTIONS_H 67 return (ceil(x / pow(10.0, decPow))) * pow(10.0, decPow);
83 return (floor(0.5 + x / pow(10.0, decPow))) * pow(10.0, decPow);
85 return -((floor(0.5 + fabs(x) / pow(10.0, decPow))) * pow(10.0, decPow));
95 return left2 + (x - left1) * (right2 - left2) / (right1 - left1);
119 return pow(10, x) - 1;
137 template <
typename T>
142 return T(floor(x + T(0.5)));
146 return T(ceil(x - T(0.5)));
157 return std::fabs(a - b) <= tol;
168 template <
typename T>
193 template <
typename T>
194 T
gcd(T a, T b, T & u1, T & u2)
232 template <
typename T>
235 return (mz_obs - mz_ref) / mz_ref * 1e6;
247 template <
typename T>
250 return std::fabs(
getPPM(mz_obs, mz_ref));
262 template <
typename T>
265 return (ppm / 1e6) * mz_ref;
277 template <
typename T>
280 return std::fabs(
ppmToMass(ppm, mz_ref));
296 inline static std::pair<double, double>
getTolWindow(
double val,
double tol,
bool ppm)
302 left = val - val * tol * 1e-6;
303 right = val / (1.0 - tol * 1e-6);
311 return std::make_pair(left, right);
317 #endif // OPENMS_MATH_MISC_MATHFUNCTIONS_H bool isOdd(UInt x)
Returns true if the given integer is odd.
Definition: MathFunctions.h:127
static std::pair< double, double > getTolWindow(double val, double tol, bool ppm)
Return tolerance window around val given tolerance tol.
Definition: MathFunctions.h:296
unsigned int UInt
Unsigned integer type.
Definition: Types.h:95
T getPPM(T mz_obs, T mz_ref)
Compute parts-per-million of two m/z values.
Definition: MathFunctions.h:233
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
static double intervalTransformation(double x, double left1, double right1, double left2, double right2)
transforms point x of interval [left1,right1] into interval [left2,right2]
Definition: MathFunctions.h:93
T round(T x)
Rounds the value.
Definition: MathFunctions.h:138
static double ceilDecimal(double x, int decPow)
rounds x up to the next decimal power 10 ^ decPow
Definition: MathFunctions.h:65
T ppmToMassAbs(T ppm, T mz_ref)
Definition: MathFunctions.h:278
T gcd(T a, T b)
Returns the greatest common divisor (gcd) of two numbers by applying the Euclidean algorithm...
Definition: MathFunctions.h:169
static bool approximatelyEqual(double a, double b, double tol)
Returns if a is approximately equal b , allowing a tolerance of tol.
Definition: MathFunctions.h:155
double log2linear(double x)
Transforms a number from log10 to to linear scale. Subtracts the 1 added by linear2log(double) ...
Definition: MathFunctions.h:117
static double roundDecimal(double x, int decPow)
rounds x to the next decimal power 10 ^ decPow
Definition: MathFunctions.h:80
double linear2log(double x)
Transforms a number from linear to log10 scale. Avoids negative logarithms by adding 1...
Definition: MathFunctions.h:105
T getPPMAbs(T mz_obs, T mz_ref)
Compute absolute parts-per-million of two m/z values.
Definition: MathFunctions.h:248
T ppmToMass(T ppm, T mz_ref)
Compute the mass diff in [Th], given a ppm value and a reference point.
Definition: MathFunctions.h:263