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 std::transform(v.begin(), v.end(), diff.begin(), std::bind2nd(std::minus<double>(), mean));
262 double sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0);
263 double divisor = (double)v.size();
264 if (useBesselCorrection && v.size() > 1) {
265 divisor = divisor - 1;
268 return std::sqrt(sq_sum / divisor);
static int modulo(const int a, const int n)
static double getStdev(const std::vector< double > &v, const bool useBesselCorrection=false)
static double getMedian(const std::vector< double > &v)
static bool isNaN(const double value)
error that can be emited by ViSP classes.
static bool isInf(const double value)
static double sinc(double x)
static double getMean(const std::vector< double > &v)
static double mcosc(double cosx, double x)
Used to indicate that a parameter is not initialized.
static double msinc(double sinx, double x)