Merge commit 'origin/stable'
[pspp-builds.git] / src / libpspp / misc.h
index 69d3dc4f64043ef9e8929b703c3cd711c1e11d98..c2f865d90c95512d7ec4d3517c68dff96e0181d4 100644 (file)
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if !math_misc_h
-#define math_misc_h 1
+#if !libpspp_misc_h
+#define libpspp_misc_h 1
 
 #include <float.h>
 #include <math.h>
 
 #define EPSILON (10 * DBL_EPSILON)
 
-/* HUGE_VAL is traditionally defined as positive infinity, or
-   alternatively, DBL_MAX. */
-#if !HAVE_ISINF && !defined isinf
-#define isinf(X) (fabs (X) == HUGE_VAL)
-#endif
-
-/* A Not a Number is not equal to itself. */
-#if !HAVE_ISNAN && !defined isnan
-#define isnan(X) ((X) != (X))
-#endif
-
-/* Finite numbers are not infinities or NaNs. */
-#if !HAVE_FINITE && !defined finite
-#define finite(X) (!isinf (X) && !isnan (X))
-#elif HAVE_IEEEFP_H
-#include <ieeefp.h>            /* Declares finite() under Solaris. */
-#endif
-
 /* Divides nonnegative X by positive Y, rounding up. */
 #define DIV_RND_UP(X, Y) (((X) + ((Y) - 1)) / (Y))
 
@@ -78,4 +60,40 @@ pow4 (double x)
   return y;
 }
 
-#endif /* math/misc.h */
+/* Set *DEST to the lower of *DEST and SRC */
+static inline void
+minimize (double *dest, double src)
+{
+  if (src < *dest)
+    *dest = src;
+}
+
+
+/* Set *DEST to the greater of *DEST and SRC */
+static inline void
+maximize (double *dest, double src)
+{
+  if (src > *dest)
+    *dest = src;
+}
+
+
+/* Set *DEST to the lower of *DEST and SRC */
+static inline void
+minimize_int (int *dest, int src)
+{
+  if (src < *dest)
+    *dest = src;
+}
+
+
+/* Set *DEST to the greater of *DEST and SRC */
+static inline void
+maximize_int (int *dest, int src)
+{
+  if (src > *dest)
+    *dest = src;
+}
+
+
+#endif /* libpspp/misc.h */