MathToolbox.hpp
Go to the documentation of this file.
1 //
2 // MathToolbox.hpp
3 //
4 //
5 // Math functions and definitions.
6 //
8 
9 #if !defined(MATHTOOLBOX_HPP)
10 #define MATHTOOLBOX_HPP
11 
12 #include <math.h>
13 #include <cmath> // for abs()
14 #include "../BasicDatatypes.hpp"
15 
16 
17 extern double hypot(double x, double y, double z);
18 
20 extern const double NaN_double;
21 
23 
28 inline bool fuzzyCompare (double a, double b)
29 {
30  return std::abs(a - b) < 1E-11;
31 }
32 
33 //
34 // Square
35 //
36 inline double sqr(double val)
37 {
38  return val * val;
39 }
40 
42 
47 inline bool fuzzyCompare(float a, float b)
48 {
49  return std::abs(a - b) < 1E-6f;
50 }
51 
52 
53 // Normalizes an angle in radians to the interval [-pi,+pi)
54 double normalizeRadians (double radians);
55 
57 
62 template<typename floatT>
63 inline bool isNaN (floatT x)
64 {
65  return (x != x);
66 }
67 
69 
73 template<typename IntT>
74 inline IntT round_to_int (float floatValue)
75 {
76 
77  // assert (std::numeric_limits<float>::round_style == std::round_toward_zero);
78  // static_cast<IntT>() rounds toward zero
79  return IntT (floatValue + (floatValue >= 0.0f ? + 0.5f : -0.5f));
80 }
81 
83 
87 template<typename IntT>
88 inline IntT round_to_int (double floatValue)
89 {
90 
91  // assert (std::numeric_limits<double>::round_style == std::round_toward_zero);
92  // static_cast<IntT>() rounds toward zero
93  return IntT (floatValue + (floatValue >= 0.0 ? + 0.5 : -0.5));
94 }
95 
96 
97 #endif // MATHTOOLBOX
IntT round_to_int(float floatValue)
Round to the closest integer.
Definition: MathToolbox.hpp:74
double normalizeRadians(double radians)
Definition: MathToolbox.cpp:31
double hypot(double x, double y, double z)
Definition: MathToolbox.cpp:19
const double NaN_double
Not-a-Number in double precision.
Definition: MathToolbox.cpp:13
bool fuzzyCompare(double a, double b)
Tests if two double values are nearly equal.
Definition: MathToolbox.hpp:28
double sqr(double val)
Definition: MathToolbox.hpp:36
bool isNaN(floatT x)
Checks if a floating point value is Not-a-Number (NaN)
Definition: MathToolbox.hpp:63


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Sat Jun 8 2019 17:57:33