diff options
-rw-r--r-- | src/jtutil/miscfp.cc | 17 | ||||
-rw-r--r-- | src/jtutil/util.hh | 1 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/jtutil/miscfp.cc b/src/jtutil/miscfp.cc index baf164e..7b151c1 100644 --- a/src/jtutil/miscfp.cc +++ b/src/jtutil/miscfp.cc @@ -1,6 +1,7 @@ // miscfp.cc -- misc floating-point functions // +// signum - sign of a floating point number // hypot3 - 3D Euclidean distance // arctan_xy - 4-quadrant arc tangent // modulo_reduce - reduce an angle modulo 2*pi radians (360 degrees) @@ -13,6 +14,22 @@ //****************************************************************************** // +// This function computes the floating point "signum" function (as in APL), +// signum(x) = -1.0, 0.0, or +1.0, according to the sign of x. +// +namespace jtutil + { +double signum(double x) +{ +if (x == 0.0) + then return 0.0; + else return (x > 0.0) ? 1.0 : -1.0; +} + }; + +//****************************************************************************** + +// // This function computes the 3-dimensional Euclidean distance, // analogously to the standard math library function hypot(2) . // diff --git a/src/jtutil/util.hh b/src/jtutil/util.hh index 6dde8ed..089c299 100644 --- a/src/jtutil/util.hh +++ b/src/jtutil/util.hh @@ -63,6 +63,7 @@ template <typename fp> // // misc math stuff // +double signum(double x); double hypot3(double x, double y, double z); double arctan_xy(double x, double y); |