ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/math/tnt_math_utils.hpp
Revision: 1336
Committed: Tue Apr 7 20:16:26 2009 UTC (16 years ago) by gezelter
File size: 494 byte(s)
Log Message:
adding jama and tnt libraries for various linear algebra routines

File Contents

# Content
1 #ifndef MATH_UTILS_H
2 #define MATH_UTILS_H
3
4 /* needed for fabs, sqrt() below */
5 #include <cmath>
6
7
8
9 namespace TNT
10 {
11 /**
12 @returns hypotenuse of real (non-complex) scalars a and b by
13 avoiding underflow/overflow
14 using (a * sqrt( 1 + (b/a) * (b/a))), rather than
15 sqrt(a*a + b*b).
16 */
17 template <class Real>
18 Real hypot(const Real &a, const Real &b)
19 {
20
21 if (a== 0)
22 return abs(b);
23 else
24 {
25 Real c = b/a;
26 return fabs(a) * sqrt(1 + c*c);
27 }
28 }
29 } /* TNT namespace */
30
31
32
33 #endif
34 /* MATH_UTILS_H */