changeset 15214:336f42406671

use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc. * __glpk__.cc, ls-mat5.cc, data.cc, ls-oct-ascii.h, pr-output.cc, lo-utils.cc: Replace all uses of DBL_MIN, DBL_MAX, DBL_EPSILON, FLT_MIN, FLT_MAX, and FLT_EPSILON with numeric_limits functions. * variables.h (set_internal_variable): Use +/- octave_Inf as default values for minval and maxval.
author John W. Eaton <jwe@octave.org>
date Wed, 22 Aug 2012 16:30:55 -0400
parents 4bbd3bbb8912
children ae6b7ee0a733
files libinterp/dldfcn/__glpk__.cc libinterp/interp-core/ls-mat5.cc libinterp/interpfcn/data.cc libinterp/interpfcn/ls-oct-ascii.h libinterp/interpfcn/pr-output.cc libinterp/interpfcn/variables.h liboctave/lo-utils.cc
diffstat 7 files changed, 24 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/dldfcn/__glpk__.cc
+++ b/libinterp/dldfcn/__glpk__.cc
@@ -118,8 +118,8 @@
   1e-7,
   1e-7,
   1e-9,
-  -DBL_MAX,
-  DBL_MAX,
+  -std::numeric_limits<double>::max (),
+  std::numeric_limits<double>::max (),
   -1.0,
   0.0,
   1e-6,
--- a/libinterp/interp-core/ls-mat5.cc
+++ b/libinterp/interp-core/ls-mat5.cc
@@ -1939,7 +1939,7 @@
               double tmp = val[i];
 
               if (! (xisnan (tmp) || xisinf (tmp))
-                  && fabs (tmp) > FLT_MAX)
+                  && fabs (tmp) > std::numeric_limits<float>::max ())
                 {
                   too_large_for_float = true;
                   break;
--- a/libinterp/interpfcn/data.cc
+++ b/libinterp/interpfcn/data.cc
@@ -4120,7 +4120,7 @@
                 retval = fill_matrix (octave_value ("single"),
                                       lo_ieee_nan_value (),
                                       lo_ieee_float_nan_value (), "eps");
-              else if (val < FLT_MIN)
+              else if (val < std::numeric_limits<float>::min ())
                 retval = fill_matrix (octave_value ("single"), 0e0,
                                       powf (2.0, -149e0), "eps");
               else
@@ -4129,7 +4129,8 @@
                   frexpf (val, &expon);
                   val = std::pow (static_cast <float> (2.0),
                                   static_cast <float> (expon - 24));
-                  retval = fill_matrix (octave_value ("single"), DBL_EPSILON,
+                  retval = fill_matrix (octave_value ("single"),
+                                        std::numeric_limits<double>::epsilon (),
                                         val, "eps");
                 }
             }
@@ -4145,7 +4146,7 @@
                 retval = fill_matrix (octave_value_list (),
                                       lo_ieee_nan_value (),
                                       lo_ieee_float_nan_value (), "eps");
-              else if (val < DBL_MIN)
+              else if (val < std::numeric_limits<double>::min ())
                 retval = fill_matrix (octave_value_list (),
                                       pow (2.0, -1074e0), 0e0, "eps");
               else
@@ -4155,13 +4156,15 @@
                   val = std::pow (static_cast <double> (2.0),
                                   static_cast <double> (expon - 53));
                   retval = fill_matrix (octave_value_list (), val,
-                                        FLT_EPSILON, "eps");
+                                        std::numeric_limits<float>::epsilon (),
+                                        "eps");
                 }
             }
         }
     }
   else
-    retval = fill_matrix (args, DBL_EPSILON, FLT_EPSILON, "eps");
+    retval = fill_matrix (args, std::numeric_limits<double>::epsilon (),
+                          std::numeric_limits<float>::epsilon (), "eps");
 
   return retval;
 }
@@ -4259,7 +4262,8 @@
 @seealso{realmin, intmax, bitmax, eps}\n\
 @end deftypefn")
 {
-  return fill_matrix (args, DBL_MAX, FLT_MAX, "realmax");
+  return fill_matrix (args, std::numeric_limits<double>::max (),
+                      std::numeric_limits<float>::max (), "realmax");
 }
 
 DEFUN (realmin, args, ,
@@ -4292,7 +4296,8 @@
 @seealso{realmax, intmin, eps}\n\
 @end deftypefn")
 {
-  return fill_matrix (args, DBL_MIN, FLT_MIN, "realmin");
+  return fill_matrix (args, std::numeric_limits<double>::min (),
+                      std::numeric_limits<float>::min (), "realmin");
 }
 
 DEFUN (I, args, ,
--- a/libinterp/interpfcn/ls-oct-ascii.h
+++ b/libinterp/interpfcn/ls-oct-ascii.h
@@ -38,7 +38,7 @@
 // Used when converting Inf to something that gnuplot can read.
 
 #ifndef OCT_RBV
-#define OCT_RBV DBL_MAX / 100.0
+#define OCT_RBV (std::numeric_limits<double>::max () / 100.0)
 #endif
 
 extern OCTINTERP_API std::string
--- a/libinterp/interpfcn/pr-output.cc
+++ b/libinterp/interpfcn/pr-output.cc
@@ -483,7 +483,7 @@
   octave_idx_type nr = m.rows ();
   octave_idx_type nc = m.columns ();
 
-  double result = -DBL_MAX;
+  double result = -std::numeric_limits<double>::max ();
 
   bool all_inf_or_nan = true;
 
@@ -512,7 +512,7 @@
   octave_idx_type nr = m.rows ();
   octave_idx_type nc = m.columns ();
 
-  double result = DBL_MAX;
+  double result = std::numeric_limits<double>::max ();
 
   bool all_inf_or_nan = true;
 
--- a/libinterp/interpfcn/variables.h
+++ b/libinterp/interpfcn/variables.h
@@ -102,7 +102,8 @@
 extern OCTINTERP_API octave_value
 set_internal_variable (double& var, const octave_value_list& args,
                        int nargout, const char *nm,
-                       double minval = DBL_MIN, double maxval = DBL_MAX);
+                       double minval = -octave_Inf,
+                       double maxval = octave_Inf);
 
 extern OCTINTERP_API octave_value
 set_internal_variable (std::string& var, const octave_value_list& args,
--- a/liboctave/lo-utils.cc
+++ b/liboctave/lo-utils.cc
@@ -54,7 +54,10 @@
 { return x == 0; }
 
 bool xtoo_large_for_float (double x)
-{ return (! (xisnan (x) || xisinf (x)) && fabs (x) > FLT_MAX); }
+{
+  return (! (xisnan (x) || xisinf (x))
+          && fabs (x) > std::numeric_limits<float>::max ());
+}
 
 bool xtoo_large_for_float (const Complex& x)
 {