summaryrefslogtreecommitdiffstats
path: root/extra/libofa/tnt_math_utils.h
diff options
context:
space:
mode:
authorThierry N <thierryn1 at hispeed dot ch>2009-08-11 19:37:32 +0200
committerThierry N <thierryn1 at hispeed dot ch>2009-08-11 19:37:32 +0200
commit7387aff001124619ba311547546d43169a1e94e5 (patch)
tree666d8d45f840d55b552a9b02f523f67672eb6148 /extra/libofa/tnt_math_utils.h
parent8b8f45a246f9516bb78b10cdd514298ce4ee8f2a (diff)
downloadnutyx-extra-7387aff001124619ba311547546d43169a1e94e5.tar.gz
nutyx-extra-7387aff001124619ba311547546d43169a1e94e5.tar.bz2
nutyx-extra-7387aff001124619ba311547546d43169a1e94e5.tar.xz
nutyx-extra-7387aff001124619ba311547546d43169a1e94e5.zip
Ajout de libofa#0.9.3-1
Diffstat (limited to 'extra/libofa/tnt_math_utils.h')
-rw-r--r--extra/libofa/tnt_math_utils.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/extra/libofa/tnt_math_utils.h b/extra/libofa/tnt_math_utils.h
new file mode 100644
index 000000000..40de63f05
--- /dev/null
+++ b/extra/libofa/tnt_math_utils.h
@@ -0,0 +1,70 @@
+#ifndef MATH_UTILS_H
+#define MATH_UTILS_H
+
+#include <math.h>
+/* needed for sqrt() below */
+
+#ifdef PREANSI
+template <class _Tp>
+inline const _Tp& min(const _Tp& __a, const _Tp& __b) {
+ return __b < __a ? __b : __a;
+}
+
+template <class _Tp>
+inline const _Tp& max(const _Tp& __a, const _Tp& __b) {
+ return __a < __b ? __b : __a;
+}
+#endif
+
+
+namespace TNT
+{
+/**
+ @returns the absolute value of a real (no-complex) scalar.
+*/
+template <class Real>
+Real abs(const Real &a)
+{
+ return (a > 0 ? a : -a);
+}
+/**
+
+ @returns hypotenuse of real (non-complex) scalars a and b by
+ avoiding underflow/overflow
+ using (a * sqrt( 1 + (b/a) * (b/a))), rather than
+ sqrt(a*a + b*b).
+*/
+template <class Real>
+Real hypot(const Real &a, const Real &b)
+{
+
+ if (a== 0)
+ return abs(b);
+ else
+ {
+ Real c = b/a;
+ return a * sqrt(1 + c*c);
+ }
+}
+
+/**
+ @returns the minimum of scalars a and b.
+template <class Scalar>
+Scalar min(const Scalar &a, const Scalar &b)
+{
+ return a < b ? a : b;
+}
+*/
+
+/**
+ @returns the maximum of scalars a and b.
+template <class Scalar>
+Scalar max(const Scalar &a, const Scalar &b)
+{
+ return a > b ? a : b;
+}
+*/
+
+}
+#endif
+/* MATH_UTILS_H */