Main Page   Namespace List   Compound List   File List   Namespace Members   Compound Members   File Members  

tnt_math_utils.h

Go to the documentation of this file.
00001 #ifndef MATH_UTILS_H
00002 #define MATH_UTILS_H
00003 
00004 #include <math.h>
00005 /* needed for sqrt() below */
00006 
00007 
00008 
00009 namespace TNT
00010 {
00017 template <class Real>
00018 Real hypot(const Real &a, const Real &b)
00019 {
00020         
00021         if (a== 0)
00022                 return abs(b);
00023         else
00024         {
00025                 Real c = b/a;
00026                 return abs(a) * sqrt(1 + c*c);
00027         }
00028 }
00029 
00033 template <class Scalar>
00034 Scalar min(const Scalar &a, const Scalar &b)
00035 {
00036         return  a < b ? a : b;
00037 }
00038 
00042 template <class Scalar>
00043 Scalar max(const Scalar &a, const Scalar &b)
00044 {
00045         return  a > b ? a : b;
00046 }
00047 
00051 template <class Real>
00052 Real abs(const Real &a)
00053 {
00054         return  (a > 0 ? a : -a);
00055 }
00056 
00057 }
00058 
00059 
00060 
00061 
00062 #endif
00063 /* MATH_UTILS_H */

Generated at Thu Jun 26 17:26:14 2003 for Template Numerical Toolkit (TNT) by doxygen1.2.5 written by Dimitri van Heesch, © 1997-2001