49 #include <visp3/core/vpMath.h>
50 #include <visp3/core/vpException.h>
52 #if defined(VISP_HAVE_FUNC__ISNAN)
56 #if !(defined(VISP_HAVE_FUNC_ISNAN) || defined(VISP_HAVE_FUNC_STD_ISNAN)) || !(defined(VISP_HAVE_FUNC_ISINF) || defined(VISP_HAVE_FUNC_STD_ISINF))
57 # if defined _MSC_VER || defined __BORLANDC__
58 typedef __int64 int64;
59 typedef unsigned __int64 uint64;
61 typedef int64_t int64;
62 typedef uint64_t uint64;
65 #ifndef DOXYGEN_SHOULD_SKIP_THIS
76 const double vpMath::ang_min_sinc = 1.0e-8;
77 const double vpMath::ang_min_mc = 2.5e-4;
87 #if defined(VISP_HAVE_FUNC_ISNAN)
89 #elif defined(VISP_HAVE_FUNC_STD_ISNAN)
90 return std::isnan(value);
91 #elif defined(VISP_HAVE_FUNC__ISNAN)
92 return (_isnan(value) != 0);
97 return (value != value);
102 return (((
unsigned)(ieee754.u >> 32) & 0x7fffffff) +
103 ((
unsigned)ieee754.u != 0) > 0x7ff00000) != 0;
114 #if defined(VISP_HAVE_FUNC_ISINF)
116 #elif defined(VISP_HAVE_FUNC_STD_ISINF)
117 return std::isinf(value);
118 #elif defined(VISP_HAVE_FUNC__FINITE)
119 return !_finite(value);
124 return ((
unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 &&
125 (unsigned)ieee754.u == 0;
140 if (fabs(x) < ang_min_mc)
return 0.5 ;
141 else return ((1.0-cosx)/x/x) ;
156 if (fabs(x) < ang_min_mc)
return (1./6.0) ;
157 else return ((1.0-sinx/x)/x/x) ;
171 if (fabs(x) < ang_min_sinc)
return 1.0 ;
172 else return sin(x)/x ;
186 if (fabs(x) < ang_min_sinc)
return 1.0 ;
187 else return (sinx/x) ;
203 size_t size = v.size();
205 double sum = std::accumulate(v.begin(), v.end(), 0.0);
207 return sum / (double) size;
223 std::vector<double> v_copy = v;
224 size_t size = v_copy.size();
227 sort(v_copy.begin(), v_copy.end());
228 median = (v_copy[size / 2 - 1] + v_copy[size / 2]) / 2.0;
230 std::nth_element(v_copy.begin(), v_copy.begin() + (int) (size/2), v_copy.end());
231 median = v_copy[size/2];
252 std::vector<double> diff(v.size());
253 std::transform(v.begin(), v.end(), diff.begin(),
254 std::bind2nd(std::minus<double>(), mean));
255 double sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0);
256 double divisor = (double) v.size();
257 if(useBesselCorrection && v.size() > 1) {
261 return std::sqrt(sq_sum / divisor);
275 return ((a % n) + n) % n;
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)
static double msinc(double sinx, double x)