update from texinfo
[gnulib.git] / tests / test-isnanl.h
1 /* Test of isnanl() substitute.
2    Copyright (C) 2007 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
19
20 #include <limits.h>
21 #include <stdlib.h>
22
23 #define ASSERT(expr) if (!(expr)) abort ();
24
25 int
26 main ()
27 {
28   /* Finite values.  */
29   ASSERT (!isnanl (3.141L));
30   ASSERT (!isnanl (3.141e30L));
31   ASSERT (!isnanl (3.141e-30L));
32   ASSERT (!isnanl (-2.718L));
33   ASSERT (!isnanl (-2.718e30L));
34   ASSERT (!isnanl (-2.718e-30L));
35   /* Infinite values.  */
36   ASSERT (!isnanl (1.0L / 0.0L));
37   ASSERT (!isnanl (-1.0L / 0.0L));
38   /* Quiet NaN.  */
39   ASSERT (isnanl (0.0L / 0.0L));
40 #if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
41   /* Signalling NaN.  */
42   {
43     #define NWORDS \
44       ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
45     typedef union { long double value; unsigned int word[NWORDS]; }
46             memory_long_double;
47     memory_long_double m;
48     m.value = 0.0L / 0.0L;
49 # if LDBL_EXPBIT0_BIT > 0
50     m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
51 # else
52     m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
53       ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
54 # endif
55     m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
56       |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
57     ASSERT (isnanl (m.value));
58   }
59 #endif
60   return 0;
61 }