00001 #ifndef vnl_math_h_
00002 #define vnl_math_h_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <vcl_cmath.h>
00030 #include "dll.h"
00031
00032
00033 template <class T> T vnl_huge_val(T);
00034 double vnl_huge_val(double);
00035 float vnl_huge_val(float);
00036 long int vnl_huge_val(long int);
00037 int vnl_huge_val(int);
00038 short vnl_huge_val(short);
00039 char vnl_huge_val(char);
00040
00041
00042 class vnl_math {
00043 public:
00044
00045 static VNL_DLL_DATA double const e VCL_STATIC_CONST_INIT_FLOAT(2.7182818284590452354);
00046 static VNL_DLL_DATA double const log2e VCL_STATIC_CONST_INIT_FLOAT(1.4426950408889634074);
00047 static VNL_DLL_DATA double const log10e VCL_STATIC_CONST_INIT_FLOAT(0.43429448190325182765);
00048 static VNL_DLL_DATA double const ln2 VCL_STATIC_CONST_INIT_FLOAT(0.69314718055994530942);
00049 static VNL_DLL_DATA double const ln10 VCL_STATIC_CONST_INIT_FLOAT(2.30258509299404568402);
00050 static VNL_DLL_DATA double const pi VCL_STATIC_CONST_INIT_FLOAT(3.14159265358979323846);
00051 static VNL_DLL_DATA double const pi_over_2 VCL_STATIC_CONST_INIT_FLOAT(1.57079632679489661923);
00052 static VNL_DLL_DATA double const pi_over_4 VCL_STATIC_CONST_INIT_FLOAT(0.78539816339744830962);
00053 static VNL_DLL_DATA double const one_over_pi VCL_STATIC_CONST_INIT_FLOAT(0.31830988618379067154);
00054 static VNL_DLL_DATA double const two_over_pi VCL_STATIC_CONST_INIT_FLOAT(0.63661977236758134308);
00055 static VNL_DLL_DATA double const two_over_sqrtpi VCL_STATIC_CONST_INIT_FLOAT(1.12837916709551257390);
00056 static VNL_DLL_DATA double const sqrt2 VCL_STATIC_CONST_INIT_FLOAT(1.41421356237309504880);
00057 static VNL_DLL_DATA double const sqrt1_2 VCL_STATIC_CONST_INIT_FLOAT(0.70710678118654752440);
00058
00059
00060 static VNL_DLL_DATA double const eps VCL_STATIC_CONST_INIT_FLOAT(2.2204460492503131e-16);
00061 static VNL_DLL_DATA double const sqrteps VCL_STATIC_CONST_INIT_FLOAT(1.490116119384766e-08);
00062
00063
00064
00065
00066 static VNL_DLL_DATA int const maxint;
00067 static VNL_DLL_DATA long int const maxlong;
00068 static VNL_DLL_DATA double const maxdouble;
00069 static VNL_DLL_DATA float const maxfloat;
00070 };
00071
00072
00073 template <class T> inline bool vnl_math_isnan(T ) { return false; }
00074 bool vnl_math_isnan(float);
00075 bool vnl_math_isnan(double);
00076 bool vnl_math_isnan(long double);
00077
00078
00079 template <class T> inline bool vnl_math_isinf(T ) { return false; }
00080 bool vnl_math_isinf(float);
00081 bool vnl_math_isinf(double);
00082 bool vnl_math_isinf(long double);
00083
00084
00085 template <class T> inline bool vnl_math_isfinite(T ) { return false; }
00086 bool vnl_math_isfinite(float);
00087 bool vnl_math_isfinite(double);
00088 bool vnl_math_isfinite(long double);
00089
00090
00091 inline long vnl_math_rnd(float x) { return (x>=0.0)?(int)(x + 0.5):(int)(x - 0.5); }
00092 inline int vnl_math_rnd(double x) { return (x>=0.0)?(int)(x + 0.5):(int)(x - 0.5); }
00093
00094
00095 inline int vnl_math_abs(int x) { return x < 0 ? -x : x; }
00096 inline unsigned vnl_math_abs(unsigned x) { return x; }
00097 inline long vnl_math_abs(long x) { return x < 0 ? -x : x; }
00098 inline unsigned long vnl_math_abs(unsigned long x) { return x; }
00099 inline float vnl_math_abs(float x) { return x < 0.0 ? -x : x; }
00100 inline double vnl_math_abs(double x) { return x < 0.0 ? -x : x; }
00101 inline long double vnl_math_abs(long double x) { return x < 0 ? -x : x; }
00102
00103
00104 inline int vnl_math_max(int x, int y) { return (x > y) ? x : y; }
00105 inline unsigned vnl_math_max(unsigned x, unsigned y) { return (x > y) ? x : y; }
00106 inline long vnl_math_max(long x, long y) { return (x > y) ? x : y; }
00107 inline float vnl_math_max(float x, float y) { return (x < y) ? y : x; }
00108 inline double vnl_math_max(double x, double y) { return (x < y) ? y : x; }
00109
00110
00111 inline int vnl_math_min(int x, int y) { return (x < y) ? x : y; }
00112 inline unsigned vnl_math_min(unsigned x, unsigned y) { return (x < y) ? x : y; }
00113 inline long vnl_math_min(long x, long y) { return (x < y) ? x : y; }
00114 inline float vnl_math_min(float x, float y) { return (x > y) ? y : x; }
00115 inline double vnl_math_min(double x, double y) { return (x > y) ? y : x; }
00116
00117
00118 inline int vnl_math_sqr(int x) { return x*x; }
00119 inline unsigned vnl_math_sqr(unsigned x) { return x*x; }
00120 inline long vnl_math_sqr(long x) { return x*x; }
00121 inline float vnl_math_sqr(float x) { return x*x; }
00122 inline double vnl_math_sqr(double x) { return x*x; }
00123
00124
00125 inline int vnl_math_sgn(int x) { return x?((x>0)?1:-1):0; }
00126 inline int vnl_math_sgn(long x) { return x?((x>0)?1:-1):0; }
00127 inline int vnl_math_sgn(float x) { return (x != 0)?((x>0)?1:-1):0; }
00128 inline int vnl_math_sgn(double x) { return (x != 0)?((x>0)?1:-1):0; }
00129
00130
00131 inline int vnl_math_sgn0(int x) { return (x>=0)?1:-1; }
00132 inline int vnl_math_sgn0(long x) { return (x>=0)?1:-1; }
00133 inline int vnl_math_sgn0(float x) { return (x>=0)?1:-1; }
00134 inline int vnl_math_sgn0(double x) { return (x>=0)?1:-1; }
00135
00136
00137 inline int vnl_math_squared_magnitude(int x) { return x*x; }
00138 inline unsigned vnl_math_squared_magnitude(unsigned x) { return x*x; }
00139 inline long vnl_math_squared_magnitude(long x) { return x*x; }
00140 inline unsigned long vnl_math_squared_magnitude(unsigned long x) { return x*x; }
00141 inline float vnl_math_squared_magnitude(float x) { return x*x; }
00142 inline double vnl_math_squared_magnitude(double x) { return x*x; }
00143 inline long double vnl_math_squared_magnitude(long double x) { return x*x; }
00144
00145
00146 inline float vnl_math_sqrt(float x) { return float( vcl_sqrt(double(x))); }
00147 inline double vnl_math_sqrt(double x) { return vcl_sqrt(double(x)) ; }
00148
00149
00150 inline float vnl_math_cuberoot(float a) { return float((a<0) ? -vcl_exp(vcl_log(-a)/3) : vcl_exp(vcl_log(a)/3)); }
00151 inline double vnl_math_cuberoot(double a) { return (a<0) ? -vcl_exp(vcl_log(-a)/3) : vcl_exp(vcl_log(a)/3); }
00152
00153
00154 inline double vnl_math_hypot(int x, int y) { return vcl_sqrt(double(x*x + y*y)); }
00155 inline float vnl_math_hypot(float x, float y) { return float( vcl_sqrt(double(x*x + y*y)) ); }
00156 inline double vnl_math_hypot(double x, double y) { return vcl_sqrt(x*x + y*y); }
00157
00158 #endif // vnl_math_h_