changeset 6492:bcfdc9f0d267

[project @ 2007-04-05 06:13:30 by jwe]
author jwe
date Thu, 05 Apr 2007 06:13:30 +0000
parents 95e9ba7cb502
children 5fa513371dde
files src/ChangeLog src/oct-stream.cc
diffstat 2 files changed, 59 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Apr 05 03:12:54 2007 +0000
+++ b/src/ChangeLog	Thu Apr 05 06:13:30 2007 +0000
@@ -1,3 +1,8 @@
+2007-04-05  John W. Eaton  <jwe@octave.org>
+
+	* oct-stream.cc (DO_DOUBLE_CONV): New macro.
+	(do_printf): Use it.
+
 2007-04-04  John W. Eaton  <jwe@octave.org>
 
 	* input.cc (octave_yes_or_no): Force interactive_input to use readline.
--- a/src/oct-stream.cc	Thu Apr 05 03:12:54 2007 +0000
+++ b/src/oct-stream.cc	Thu Apr 05 06:13:30 2007 +0000
@@ -2479,6 +2479,45 @@
 do_printf_conv (std::ostream&, const char*, int, int, int, const char*,
 		const std::string&);
 
+#define DO_DOUBLE_CONV(TQUAL) \
+  do \
+    { \
+      if (elt->modifier == 'l') \
+	{ \
+	  if (val > std::numeric_limits<TQUAL long>::max () \
+	      || val < std::numeric_limits<TQUAL long>::min ()) \
+	    { \
+	      std::string tfmt = fmt; \
+ \
+	      tfmt.replace (tfmt.rfind (elt->type), 1, ".f"); \
+	      tfmt.replace (tfmt.rfind (elt->modifier), 1, ""); \
+ \
+	      retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, \
+					val, who); \
+	    } \
+	  else \
+	    retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, \
+				      static_cast<TQUAL long> (val), who); \
+	} \
+      else \
+	{ \
+	  if (val > std::numeric_limits<TQUAL int>::max () \
+	      || val < std::numeric_limits<TQUAL int>::min ()) \
+	    { \
+	      std::string tfmt = fmt; \
+ \
+	      tfmt.replace (tfmt.rfind (elt->type), 1, ".f"); \
+ \
+	      retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, \
+					val, who); \
+	    } \
+	  else \
+	    retval += do_printf_conv (os, fmt, nsa, sa_1, sa_2, \
+				      static_cast<TQUAL int> (val), who); \
+	} \
+    } \
+  while (0)
+
 int
 octave_base_stream::do_printf (printf_format_list& fmt_list,
 			       const octave_value_list& args,
@@ -2557,68 +2596,32 @@
 
 		  if (val_cache)
 		    {
-		      if (lo_ieee_isnan (val) || xisinf (val)
-			  || ((val > INT_MAX || val < INT_MIN)
-			      && (elt->type == 'd'
-				  || elt->type == 'i'
-				  || elt->type == 'c'
-				  || elt->type == 'o'
-				  || elt->type == 'x'
-				  || elt->type == 'X'
-				  || elt->type == 'u')))
+		      if (lo_ieee_isnan (val) || xisinf (val))
 			{
 			  std::string tfmt = fmt;
 
-			  if (lo_ieee_isnan (val) || xisinf (val))
-			    {
-			      tfmt.replace (tfmt.rfind (elt->type), 1, 1, 's');
-
-			      const char *tval = xisinf (val)
-				? (val < 0 ? "-Inf" : "Inf")
-				: (lo_ieee_is_NA (val) ? "NA" : "NaN");
-
-			      retval += do_printf_conv (os, tfmt.c_str (),
-							nsa, sa_1, sa_2,
-							tval, who);
-			    }
-			  else
-			    {
-			      tfmt.replace (tfmt.rfind (elt->type), 1, ".f");
-
-			      retval += do_printf_conv (os, tfmt.c_str (),
-							nsa, sa_1, sa_2,
-							val, who);
-			    }
+			  tfmt.replace (tfmt.rfind (elt->type), 1, 1, 's');
+
+			  const char *tval = xisinf (val)
+			    ? (val < 0 ? "-Inf" : "Inf")
+			    : (lo_ieee_is_NA (val) ? "NA" : "NaN");
+
+			  retval += do_printf_conv (os, tfmt.c_str (),
+						    nsa, sa_1, sa_2,
+						    tval, who);
 			}
 		      else
 			{
-			  switch (elt->type)
+			  char type = elt->type;
+
+			  switch (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), who);
-				else
-				  retval += do_printf_conv
-				    (os, fmt, nsa, sa_1, sa_2,
-				     static_cast<int> (val), who);
-			      }
+			      DO_DOUBLE_CONV ( );
 			      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),
-				     who);
-				else
-				  retval += do_printf_conv
-				    (os, fmt, nsa, sa_1, sa_2,
-				     static_cast<unsigned int> (val), who);
-			      }
+			      DO_DOUBLE_CONV (unsigned);
 			      break;
 
 			    case 'f': case 'e': case 'E':