This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
A questions about NaN and Infinity in GCC
- From: Yao Qi <qiyaoltc at cn dot ibm dot com>
- To: gcc <gcc at gcc dot gnu dot org>
- Date: Tue, 06 Sep 2005 13:48:16 +0800
- Subject: A questions about NaN and Infinity in GCC
I am work on a floating points test according to IEEE754 and IEEE754 specifies
that seven invalid arithmetic operations shall deliver a NaN unless they are
trapped:
sqrt(Negative), 0*Infinity, 0.0/0.0, Infinity/Infinity, REMAINDER(Anything,0.0),
REMAINDER(Infinity, Anything), Infinity - Infinity.
I write a small case to verify part of this, and I list the source code here for
your reference,
1 #include<stdio.h>
2
3 int main()
4 {
5 /* INF - INF => NaN. */
6 if ((__builtin_inf() - __builtin_inf()) != __builtin_nan(""))
7 printf("error 1\n");
8 /* 0 * INF => NaN. */
9 if ((0*__builtin_inf()) != __builtin_nan(""))
10 printf("error 2\n");
11 /* INF/INF => NaN. */
12 if ((__builtin_inf()/__builtin_inf()) != __builtin_nan(""))
13 printf("error 3\n");
14 /* INF + INF => INF. */
15 if ((__builtin_inf() + __builtin_inf()) != __builtin_inf())
16 printf("error 4\n");
17 if (0.0/0.0 != __builtin_nan(""))
18 printf("error 5\n");
19
20 return 0;
21 }
And I compile it like this:
[qiyao@ qiyao]$ gcc -o nan-3 nan-3.c
And run it,
[qiyao@ qiyao]$ ./nan-3
error 1
error 2
error 3
error 5
It seems that the result do not obey IEEE754. I am not so sure about it, Anyone
could confirm or deny this? Thanks in advance!
--
Regards, Yao
Yao Qi