Hello!

Probably I'm doing something wrong, but I have some problems comparing a double 
with NAN: The value is NAN, but the test fails. Probably I should use isnana().
Here's my test case:
---
#include <math.h>
#include <assert.h>

int     main()
{
        double d = NAN;

        assert(d == NAN);
        return 0;
}
---
The output is:
---
> ./foo
foo: foo.c:8: main: Assertion `d == (__builtin_nanf (""))' failed.
Aborted
---
Code is:
---
Dump of assembler code for function main:
   0x000000000040059a <+0>:     push   %rbp
   0x000000000040059b <+1>:     mov    %rsp,%rbp
   0x000000000040059e <+4>:     sub    $0x10,%rsp
   0x00000000004005a2 <+8>:     mov    %fs:0x28,%rax
   0x00000000004005ab <+17>:    mov    %rax,-0x8(%rbp)
   0x00000000004005af <+21>:    xor    %eax,%eax
   0x00000000004005b1 <+23>:    movabs $0x7ff8000000000000,%rax
   0x00000000004005bb <+33>:    mov    %rax,-0x10(%rbp)
   0x00000000004005bf <+37>:    mov    $0x4006d4,%ecx
   0x00000000004005c4 <+42>:    mov    $0x8,%edx
   0x00000000004005c9 <+47>:    mov    $0x4006d9,%esi
   0x00000000004005ce <+52>:    mov    $0x4006df,%edi
   0x00000000004005d3 <+57>:    callq  0x400490 <__assert_fail@plt>
End of assembler dump.
Breakpoint 1, main () at foo.c:8
8               assert(d == NAN);
(gdb) p d
$1 = nan(0x8000000000000)
---

Interestingly this always fails: "assert(NAN == NAN);".

Is this a bug in the compiler or the implementation? If not, can there be a 
warning about such? I'm using an old "gcc-4_3-branch revision 152973".

Regards,
Ulrich


Reply via email to