octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparison with NaN


From: Jaroslav Hajek
Subject: Re: Comparison with NaN
Date: Mon, 11 May 2009 10:29:55 +0200

On Mon, May 11, 2009 at 10:11 AM, Michael Goffioul
<address@hidden> wrote:
> On Mon, May 11, 2009 at 6:35 AM, Jaroslav Hajek <address@hidden> wrote:
>> On Sun, May 10, 2009 at 10:43 PM, Michael Goffioul
>> <address@hidden> wrote:
>>> Hi,
>>>
>>> After running the test suite, I get a couple of errors. All of these
>>> seem to be related to comparing/sorting with NaN. For instance:
>>>
>>> assert (sort ([NaN, 1, -1, 2, Inf], 2),[-1, 1, 2, Inf, NaN]) expected
>>>    -1     1     2   Inf   NaN
>>> but got
>>>   NaN    -1     1     2   Inf
>>>
>>> Can anybody tell me what is the expected behavior?
>>>
>>
>> The assertion result indicates the expected behavior.
>
> Of course. My question was badly formulated, my fault.
> I meant what is the standard C++ NaN comparison bevahior,
> that I could test in a simple test program.

I think the current C++ standard knows nothing about NaNs (only allows
them), so the authority should be IEEE 754 and perhaps C99. Of course,
NaNs should yield false when involved in all sorts of standard
comparisons (unlike some C99 specials), but that is not relevant here,
since it should actually never happen inside sort's implementation.

>> I can't
>> reproduce the problem. Hmmm. Can you try the attached test patch and
>> tell me whether the message gets printed after running `sort ([NaN, 1,
>> -1, 2, Inf], 2)' ? (it will be only printed once, so if you have some
>> startup scripts calling sort with doubles, it should get printed
>> earlier).
>
> I'll test that ASAP (probably this evening).
>

OK. Just FYI, I'll be travelling tuesday-thursday, so I won't be able
to respond during that period.

>
>> Plus, please tell me the status of HAVE_CMATH_ISNAN in your config.h.
>
> It's not defined. MSVC uses _isnan instead, so I assume that
> std::_isnan would exist, though I didn't test yet.
> (altough http://msdn.microsoft.com/en-us/library/7wsh95e5.aspx seems to
> indicate that cmath does not define isnan).
>

Thx, good to know. The test just assumes that is std::isnan exists in
<cmath>, it's very likely to be C99-compliant and thus probably by far
the best choice to use. But if that's not the case, the old (and
usually slower) codes in lo-ieee take place, so it should still be OK
if you don't see problems with other tests (a malfunctioning isnan
should break dozens of other tests).

regards

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]