50 #include <visp3/core/vpException.h> 51 #include <visp3/core/vpMath.h> 53 #if defined(VISP_HAVE_FUNC__ISNAN) 57 #if !(defined(VISP_HAVE_FUNC_ISNAN) || defined(VISP_HAVE_FUNC_STD_ISNAN)) || \ 58 !(defined(VISP_HAVE_FUNC_ISINF) || defined(VISP_HAVE_FUNC_STD_ISINF)) 59 #if defined _MSC_VER || defined __BORLANDC__ 60 typedef __int64 int64;
61 typedef unsigned __int64 uint64;
63 typedef int64_t int64;
64 typedef uint64_t uint64;
67 #ifndef DOXYGEN_SHOULD_SKIP_THIS 68 typedef union Cv64suf {
76 const double vpMath::ang_min_sinc = 1.0e-8;
77 const double vpMath::ang_min_mc = 2.5e-4;
86 #if defined(VISP_HAVE_FUNC_ISNAN) 88 #elif defined(VISP_HAVE_FUNC_STD_ISNAN) 89 return std::isnan(value);
90 #elif defined(VISP_HAVE_FUNC__ISNAN) 91 return (_isnan(value) != 0);
96 return (value != value);
101 return (((
unsigned)(ieee754.u >> 32) & 0x7fffffff) + ((
unsigned)ieee754.u != 0) > 0x7ff00000) != 0;
112 #if defined(VISP_HAVE_FUNC_ISINF) 114 #elif defined(VISP_HAVE_FUNC_STD_ISINF) 115 return std::isinf(value);
116 #elif defined(VISP_HAVE_FUNC__FINITE) 117 return !_finite(value);
122 return ((
unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 && (unsigned)ieee754.u == 0;
137 if (fabs(x) < ang_min_mc)
140 return ((1.0 - cosx) / x / x);
155 if (fabs(x) < ang_min_mc)
158 return ((1.0 - sinx / x) / x / x);
172 if (fabs(x) < ang_min_sinc)
189 if (fabs(x) < ang_min_sinc)
208 size_t size = v.size();
210 double sum = std::accumulate(v.begin(), v.end(), 0.0);
212 return sum / (double)size;
228 std::vector<double> v_copy = v;
229 size_t size = v_copy.size();
232 std::nth_element(v_copy.begin(), v_copy.begin() + n, v_copy.end());
233 double val_n = v_copy[n];
238 std::nth_element(v_copy.begin(), v_copy.begin() + n - 1, v_copy.end());
239 return 0.5 * (val_n + v_copy[n - 1]);
258 double mean = getMean(v);
260 std::vector<double> diff(v.size());
261 #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98 262 std::transform(v.begin(), v.end(), diff.begin(), std::bind(std::minus<double>(), std::placeholders::_1, mean));
264 std::transform(v.begin(), v.end(), diff.begin(), std::bind2nd(std::minus<double>(), mean));
267 double sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0);
268 double divisor = (double)v.size();
269 if (useBesselCorrection && v.size() > 1) {
270 divisor = divisor - 1;
273 return std::sqrt(sq_sum / divisor);
static double getMedian(const std::vector< double > &v)
static double getStdev(const std::vector< double > &v, bool useBesselCorrection=false)
error that can be emited by ViSP classes.
static double sinc(double x)
static double getMean(const std::vector< double > &v)
static double mcosc(double cosx, double x)
static bool isNaN(double value)
Used to indicate that a parameter is not initialized.
static bool isInf(double value)
static int modulo(int a, int n)
static double msinc(double sinx, double x)