vnl_math.cxx
Go to the documentation of this file.
1 // This is core/vnl/vnl_math.cxx
2 //:
3 // \file
4 
5 #include <limits>
6 #include <cmath>
7 #include "vnl_math.h"
8 
9 //----------------------------------------------------------------------
10 //: Type-accessible infinities for use in templates.
11 template <class T> T vnl_huge_val(T);
12 float vnl_huge_val(float) { return std::numeric_limits<float>::infinity(); }
13 double vnl_huge_val(double) { return std::numeric_limits<double>::infinity(); }
14 long double vnl_huge_val(long double) { return std::numeric_limits<long double>::infinity(); }
15 
16 #ifdef _INT_64BIT_
17 long int vnl_huge_val(long int) { return 0x7fffffffffffffffL; }
18 int vnl_huge_val(int) { return 0x7fffffffffffffffL; }
19 #else
20 int vnl_huge_val(int) { return 0x7fffffff; }
21 #endif
22 short vnl_huge_val(short) { return 0x7fff; }
23 char vnl_huge_val(char) { return 0x7f; }
24 
25 
26 //----------------------------------------------------------------------
27 namespace vnl_math
28 {
29 double angle_0_to_2pi(double angle)
30 {
31  angle = std::fmod(angle, vnl_math::twopi);
32  if (angle >= 0) return angle;
33  double a = angle + vnl_math::twopi;
34  if (a > 0 && a < vnl_math::twopi) return a;
35  // added by Nhon: this fixes a bug when angle >= -1.1721201390607859e-016 :
36  // then after the above computation we get 6.2831853071795864769 == twopi
37  // while this function guarantees that it returns values < twopi !!!
38  if (angle < 0) return 6.28318530717958575;
39  else return angle;
40 }
41 
42 double angle_minuspi_to_pi(double angle)
43 {
44  angle = std::fmod(angle, vnl_math::twopi);
45  if (angle> vnl_math::pi) angle -= vnl_math::twopi;
46  if (angle<-vnl_math::pi) angle += vnl_math::twopi;
47  return angle;
48 }
49 
50 }; // end namespace vnl_math
double angle_0_to_2pi(double angle)
Convert an angle to [0, 2Pi) range.
Definition: vnl_math.cxx:29
double angle_minuspi_to_pi(double angle)
Convert an angle to [-Pi, Pi) range.
Definition: vnl_math.cxx:42
Namespace with standard math functions.
T vnl_huge_val(T)
Type-accessible infinities for use in templates.
real numerical constants.
Definition: vnl_bignum.h:430
VNL_EXPORT double angle(v const &, v const &)