changeset 4303:e15a96673976

[project @ 2003-01-23 03:03:08 by jwe]
author jwe
date Thu, 23 Jan 2003 03:03:08 +0000
parents ebc2d8e4968b
children fd7d9a6e15ff
files scripts/ChangeLog scripts/general/int2str.m src/ChangeLog src/data.cc src/oct-stream.cc
diffstat 5 files changed, 96 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Wed Jan 22 22:02:23 2003 +0000
+++ b/scripts/ChangeLog	Thu Jan 23 03:03:08 2003 +0000
@@ -1,3 +1,7 @@
+2003-01-22  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* general/int2str.m: Do a better job with 0, Inf, and NaN, 
+
 2003-01-11  Paul Kienzle <pkienzle@users.sf.net>
 
 	* Makefile.in (gethelp$(BUILD_EXEEXT)): Pass $(BUILD_CXXFLAGS) and
--- a/scripts/general/int2str.m	Wed Jan 22 22:02:23 2003 +0000
+++ b/scripts/general/int2str.m	Thu Jan 23 03:03:08 2003 +0000
@@ -35,8 +35,29 @@
 
   if (nargin == 1)
     x = round (x);
-    fw = max (log10 (abs (x(:))) + 3);
-    fmt = sprintf ("%%%dd", fw);
+    t = abs (x(:));
+    t = t(t != 0);
+    if (isempty (t))
+      ## All zeros.
+      fmt = "%3d";
+    else
+      ## Maybe have some zeros.
+      nan_inf = isinf (t) | isnan (t);
+      if (any (nan_inf))
+	min_fw = 5;
+      else
+	min_fw = 3;
+      endif
+      t = t(! nan_inf);
+      if (isempty (t))
+	## Only zeros, Inf, and NaN.
+	fmt = "%5d";
+      else
+	## Could have anything.
+	fw = max (floor (max (log10 (t) + 3)), min_fw);
+	fmt = sprintf ("%%%dd", fw);
+      endif
+    endif
     fmt = strcat (repmat (fmt, 1, columns (x)), "\n");
     tmp = sprintf (fmt, round (x.'));
     tmp(length (tmp)) = "";
--- a/src/ChangeLog	Wed Jan 22 22:02:23 2003 +0000
+++ b/src/ChangeLog	Thu Jan 23 03:03:08 2003 +0000
@@ -1,5 +1,10 @@
 2003-01-22  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* oct-stream.cc (octave_base_stream::do_printf): Handle Inf and
+	NaN in int conversions for compatibility with Matlab.
+
+	* data.cc (symbols_of_data): Doc fix for realmin.
+
 	* cutils.c (octave_raw_vsnprintf): New function.
 	* utils.cc (octave_snprintf): Move here from cutils.c.
 	(octave_Vsnprintf): Likewise.  Allow octave_raw_vsnprintf to be
--- a/src/data.cc	Wed Jan 22 22:02:23 2003 +0000
+++ b/src/data.cc	Thu Jan 23 03:03:08 2003 +0000
@@ -1294,7 +1294,7 @@
     "-*- texinfo -*-\n\
 @defvr {Built-in Variable} realmax\n\
 The largest floating point number that is representable.  The actual\n\
-value is system-dependent.  On machines that support 64 bit IEEE\n\
+value is system-dependent.  On machines that support 64-bit IEEE\n\
 floating point arithmetic, @code{realmax} is approximately\n\
 @ifinfo\n\
  1.7977e+308\n\
@@ -1309,9 +1309,9 @@
   DEFCONST (realmin, DBL_MIN,
     "-*- texinfo -*-\n\
 @defvr {Built-in Variable} realmin\n\
-The smallest floating point number that is representable.  The actual\n\
-value is system-dependent.  On machines that support 64 bit IEEE\n\
-floating point arithmetic, @code{realmin} is approximately\n\
+The smallest normalized floating point number that is representable.\n\
+The actual value is system-dependent.  On machines that support\n\
+64-bit IEEE floating point arithmetic, @code{realmin} is approximately\n\
 @ifinfo\n\
  2.2251e-308\n\
 @end ifinfo\n\
--- a/src/oct-stream.cc	Wed Jan 22 22:02:23 2003 +0000
+++ b/src/oct-stream.cc	Thu Jan 23 03:03:08 2003 +0000
@@ -2298,44 +2298,67 @@
 
 		  if (val_cache)
 		    {
-		      switch (elt->type)
+		      if ((xisnan (val) || xisinf (val)
+			   && (elt->type == 'd'
+			       || elt->type == 'i'
+			       || elt->type == 'c'
+			       || elt->type == 'o'
+			       || elt->type == 'x'
+			       || elt->type == 'X'
+			       || elt->type == 'u')))
+			{
+			  std::string tfmt = fmt;
+
+			  tfmt.replace (tfmt.rfind (elt->type), 1, 1, 's');
+
+			  const char *tval = xisinf (val)
+			    ? (val < 0 ? "-Inf" : "Inf") : "NaN";
+
+			  retval += do_printf_conv (os, tfmt.c_str (),
+						    nsa, sa_1, sa_2, tval);
+			}
+		      else
 			{
-			case 'd': case 'i': case 'c':
-			  {
-			    if (elt->modifier == 'l')
-			      retval += do_printf_conv
-				(os, fmt, nsa, sa_1, sa_2,
-				 static_cast<long int> (val));
-			    else
-			      retval += do_printf_conv
-				(os, fmt, nsa, sa_1, sa_2,
-				 static_cast<int> (val));
-			  }
-			  break;
-
-			case 'o': case 'x': case 'X': case 'u':
-			  {
-			    if (elt->modifier == 'l')
-			      retval += do_printf_conv
-				(os, fmt, nsa, sa_1, sa_2,
-				 static_cast<unsigned long int> (val));
-			    else
-			      retval += do_printf_conv
-				(os, fmt, nsa, sa_1, sa_2,
-				 static_cast<unsigned int> (val));
-			  }
-			  break;
-
-			case 'f': case 'e': case 'E':
-			case 'g': case 'G':
-			  retval
-			    += do_printf_conv (os, fmt, nsa, sa_1, sa_2, val);
-			  break;
-
-			default:
-			  error ("fprintf: invalid format specifier");
-			  return -1;
-			  break;
+			  switch (elt->type)
+			    {
+			    case 'd': case 'i': case 'c':
+			      {
+				if (elt->modifier == 'l')
+				  retval += do_printf_conv
+				    (os, fmt, nsa, sa_1, sa_2,
+				     static_cast<long int> (val));
+				else
+				  retval += do_printf_conv
+				    (os, fmt, nsa, sa_1, sa_2,
+				     static_cast<int> (val));
+			      }
+			      break;
+
+			    case 'o': case 'x': case 'X': case 'u':
+			      {
+				if (elt->modifier == 'l')
+				  retval += do_printf_conv
+				    (os, fmt, nsa, sa_1, sa_2,
+				     static_cast<unsigned long int> (val));
+				else
+				  retval += do_printf_conv
+				    (os, fmt, nsa, sa_1, sa_2,
+				     static_cast<unsigned int> (val));
+			      }
+			      break;
+
+			    case 'f': case 'e': case 'E':
+			    case 'g': case 'G':
+			      retval
+				+= do_printf_conv (os, fmt, nsa, sa_1, sa_2,
+						   val);
+			      break;
+
+			    default:
+			      error ("fprintf: invalid format specifier");
+			      return -1;
+			      break;
+			    }
 			}
 		    }
 		  else