From help-octave-request at bevo dot che dot wisc dot edu Wed Sep 22 14:05:17 1999 Subject: Re: max() and min() of nan/inf From: "Joao Cardoso" To: , Date: Tue, 21 Sep 1999 23:51:00 +0100 ----- Original Message ----- From: Olli Saarela To: Joao Cardoso ; Sent: Tuesday, September 21, 1999 7:00 AM Subject: Re: max() and min() of nan/inf > Hello, > > > Is this a correct behaviour? > > > > max() or min() return nan is a nan is one of its arguments? max() or > > min() considering +/-Inf looks OK. > > Yes, it is correct. Of course this is a matter of definition (defined in > the IEEE Standard 754), but the following example tries to give some > rationale: ... > A NaN value (Not a Number) is not a real number. It doesn't have a > magnitude which could be compared. The min and max functions return the > smallest and the largest number of the set of numbers given. Yes. As NaN are not numbers, min/max should return the maximum/minimum numbers in the set, not nans. > When the > set contains a NaN, min/max should either return an error or return the min/max *number* in the set > the numbers don't any more have a minimum or a > maximum value. Hence, the value NaN is returned, indicating that there > is no number equal to the minimum or maximum value of the set. sorry. There are there numbers and not numbers. > > > arithmetic or comparition operations > > are of course not defined on nans... > > But they are defined. Any arithmethic operation with a NaN operand is > defined to evaluate to NaN. Any comparison with a NaN operand is defined > to evaluate to FALSE (except the ~= operation to TRUE). > > For example: > Is NaN bigger than 3? No. (NaN > 3) --> FALSE > Is NaN smaller than 3? No. (NaN < 3) --> FALSE > Is NaN equal to 3? No. (NaN == 3) --> FALSE using your example, max(Nan,3), if evaluated as 3>nan -> F => max:=nan but if evaluated as: nan>3 -> F => max:=3 so it is not enough to define that comparition operations on NaNs always return false, the order of evaluation also seems to be important, and that is certainly not defined in any standard. Octave has the same behaviour as matlab, in this respect. Thanks, Joao > > For more complete description, please see: > http://www.lpthe.jussieu.fr/DOC_HTML/WorkShop/common-tools/numerical_comp_gu ide/goldberg1.ps > > > Best regards, > Olli > -- > Olli Saarela KCL Development Oy > Olli dot Saarela at kcl dot fi tel. +358-9-4371538 (office) > Tekniikantie 2, Espoo-Otaniemi fax. +358-9-464305 > P.O. Box 70, FIN-02151 Espoo, Finland --------------------------------------------------------------------- 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 ---------------------------------------------------------------------