# HG changeset patch # User jwe # Date 1043290988 0 # Node ID e15a96673976ce11d739ac21de9ab07890f5c4b6 # Parent ebc2d8e4968b3fdd621cd4114f086124cba9b94b [project @ 2003-01-23 03:03:08 by jwe] diff -r ebc2d8e4968b -r e15a96673976 scripts/ChangeLog --- 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 + + * general/int2str.m: Do a better job with 0, Inf, and NaN, + 2003-01-11 Paul Kienzle * Makefile.in (gethelp$(BUILD_EXEEXT)): Pass $(BUILD_CXXFLAGS) and diff -r ebc2d8e4968b -r e15a96673976 scripts/general/int2str.m --- 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)) = ""; diff -r ebc2d8e4968b -r e15a96673976 src/ChangeLog --- 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 + * 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 diff -r ebc2d8e4968b -r e15a96673976 src/data.cc --- 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\ diff -r ebc2d8e4968b -r e15a96673976 src/oct-stream.cc --- 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 (val)); - else - retval += do_printf_conv - (os, fmt, nsa, sa_1, sa_2, - static_cast (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 (val)); - else - retval += do_printf_conv - (os, fmt, nsa, sa_1, sa_2, - static_cast (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 (val)); + else + retval += do_printf_conv + (os, fmt, nsa, sa_1, sa_2, + static_cast (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 (val)); + else + retval += do_printf_conv + (os, fmt, nsa, sa_1, sa_2, + static_cast (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