changeset 6490:0ad7655cf2bc

[project @ 2007-04-05 02:44:34 by jwe]
author jwe
date Thu, 05 Apr 2007 02:44:35 +0000
parents 39eb39d67dd8
children 95e9ba7cb502
files liboctave/ChangeLog liboctave/Range.cc liboctave/lo-utils.cc
diffstat 3 files changed, 18 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Wed Apr 04 18:59:19 2007 +0000
+++ b/liboctave/ChangeLog	Thu Apr 05 02:44:35 2007 +0000
@@ -1,3 +1,10 @@
+2007-04-04  John W. Eaton  <jwe@octave.org>
+
+	* Range.cc (Range::nelem_internal): Likewise.
+	* lo-utils.cc (NINT): Use numeric_limits<int> instead of INT_MAX.
+	(NINTbig): Use numeric_limits<octave_idx_type> instead of INT_MAX.
+	From Scott Pakin <pakin@lanl.gov>.
+
 2007-04-04  David Bateman  <dbateman@free.fr>
 
 	* dMatrix.cc (Matrix::inverse): If calc_cond is true, calculate
--- a/liboctave/Range.cc	Wed Apr 04 18:59:19 2007 +0000
+++ b/liboctave/Range.cc	Thu Apr 05 02:44:35 2007 +0000
@@ -26,10 +26,10 @@
 #endif
 
 #include <cfloat>
-#include <climits>
 #include <cmath>
 
 #include <iostream>
+#include <limits>
 
 #include "Range.h"
 #include "lo-mappers.h"
@@ -287,7 +287,7 @@
 	    n_elt++;
 	}
 
-      retval = (n_elt >= INT_MAX - 1) ? -1 : n_elt;
+      retval = (n_elt >= std::numeric_limits<octave_idx_type>::max () - 1) ? -1 : n_elt;
     }
 
   return retval;
--- a/liboctave/lo-utils.cc	Wed Apr 04 18:59:19 2007 +0000
+++ b/liboctave/lo-utils.cc	Thu Apr 05 02:44:35 2007 +0000
@@ -26,10 +26,10 @@
 #include <config.h>
 #endif
 
-#include <climits>
 #include <cstdlib>
 #include <cstdio>
 
+#include <limits>
 #include <string>
 
 #ifdef HAVE_UNISTD_H
@@ -48,15 +48,14 @@
 // this function.
 
 // Sometimes you need a large integer, but not always.
-// FIXME -- INT_MAX and INT_MIN are probably not right for 64-bits.
 
 octave_idx_type
 NINTbig (double x)
 {
-  if (x > INT_MAX)
-    return INT_MAX;
-  else if (x < INT_MIN)
-    return INT_MIN;
+  if (x > std::numeric_limits<octave_idx_type>::max ())
+    return std::numeric_limits<octave_idx_type>::max ();
+  else if (x < std::numeric_limits<octave_idx_type>::min ())
+    return std::numeric_limits<octave_idx_type>::min ();
   else
     return static_cast<octave_idx_type> ((x > 0) ? (x + 0.5) : (x - 0.5));
 }
@@ -64,10 +63,10 @@
 int
 NINT (double x)
 {
-  if (x > INT_MAX)
-    return INT_MAX;
-  else if (x < INT_MIN)
-    return INT_MIN;
+  if (x > std::numeric_limits<int>::max ())
+    return std::numeric_limits<int>::max ();
+  else if (x < std::numeric_limits<int>::min ())
+    return std::numeric_limits<int>::min ();
   else
     return static_cast<int> ((x > 0) ? (x + 0.5) : (x - 0.5));
 }