From bug-octave-request at bevo dot che dot wisc dot edu Mon Jul 12 22:51:45 1999 Subject: Min and max fail for NaN values From: "John W. Eaton" To: olli dot saarela at kcl dot fi Cc: bug-octave at bevo dot che dot wisc dot edu Date: Mon, 12 Jul 1999 22:51:29 -0500 (CDT) On 12-Jul-1999, Olli Saarela wrote: | In Octave 2.0.13, the min and max functions fail for NaN values: | | >> [min(0,NaN) min(NaN,0) max(0,NaN) max(NaN,0)] | ans = NaN 0 NaN 0 | | but the result should be | | ans = NaN NaN NaN NaN | | | minmax.cc (same source in 2.0.14 and 2.1.14) uses a definition like | | #ifndef MAX | #define MAX(a,b) ((a) > (b) ? (a) : (b)) | #endif | #ifndef MIN | ... | | This should be replaced by something like | | #undef MAX | static inline double MAX(double a, double b) { | if (a > b) { | return a; | } else { | if (isnan(a)) | return a; | return b; | } | } | #undef MIN | ... | | Similar comparisons should be used throughout at least that file. I've fixed this problem in my sources for 2.1.x, but I used a slightly different approach. Thanks, jwe --------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. To ensure that development continues, see www.che.wisc.edu/octave/giftform.html Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html ---------------------------------------------------------------------