From bug-octave-request at bevo dot che dot wisc dot edu Sat Jan 10 16:49:15 2004 Subject: 'NA' prints as 'nan' with sprintf From: "John W. Eaton" To: Pascal dot Dupuis at esat dot kuleuven dot ac dot be (Pascal A. Dupuis) Cc: bug-octave at bevo dot che dot wisc dot edu Date: Sat, 10 Jan 2004 16:48:59 -0600 On 9-Jan-2004, Pascal A. Dupuis wrote: | To: bug-octave at bevo dot che dot wisc dot edu | Subject: 'NA' prints as 'nan' with sprintf | | Bug report for Octave 2.1.50 configured for i386-pc-linux-gnu | | Description: | ----------- | | * when converted to text, NA (missing values) and nan (Not A Number) result | in the same output, namely 'nan'. My understanding is that those are | different beasts and should be printed differently. NA is a particular NaN value, but you are right that it should be printed differently. | Repeat-By: | --------- | | * sprintf('%f, %f, %f', 3, nan, 5) | -> ans = 3.000000, nan, 5.000000 | sprintf('%f, %f, %f', 3, NA, 5) | -> ans = 3.000000, nan, 5.000000 Please try the following patch. With it, I see: octave:1> sprintf('%f, %f, %f', 3, nan, 5) ans = 3.000000, NaN, 5.000000 octave:2> sprintf('%f, %f, %f', 3, NA, 5) ans = 3.000000, NA, 5.000000 Thanks, jwe 2004-01-10 John W. Eaton * oct-stream.cc (octave_base_stream::do_printf): Correct special case check for NA, NaN, Inf, or out of range integers. Index: src/oct-stream.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/oct-stream.cc,v retrieving revision 1.98 diff -u -r1.98 oct-stream.cc --- src/oct-stream.cc 10 Jan 2004 18:16:03 -0000 1.98 +++ src/oct-stream.cc 10 Jan 2004 22:45:57 -0000 at @ -2383,24 +2383,25 @@ if (val_cache) { - if ((xisnan (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_is_NaN_or_NA (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'))) { std::string tfmt = fmt; - if (xisnan (val) || xisinf (val)) + if (lo_ieee_is_NaN_or_NA (val) || xisinf (val)) { tfmt.replace (tfmt.rfind (elt->type), 1, 1, 's'); const char *tval = xisinf (val) - ? (val < 0 ? "-Inf" : "Inf") : "NaN"; + ? (val < 0 ? "-Inf" : "Inf") + : (lo_ieee_is_NA (val) ? "NA" : "NaN"); retval += do_printf_conv (os, tfmt.c_str (), nsa, sa_1, sa_2, ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------