annotate lib/isnan.c @ 11830:2e5821b6f988

doc: improve git diff of texinfo files * .gitattributes: Add rule for *.texi files, with hint on how to use it. Copied from m4, and based on a report by Bruno Haible. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Thu, 13 Aug 2009 07:15:28 -0600
parents baba3b346ab2
children 96048aa0ade9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test for NaN that does not need libm.
9673
d95fe39a37f7 Fix bug introduced on 2008-01-26.
Bruno Haible <bruno@clisp.org>
parents: 9522
diff changeset
2 Copyright (C) 2007-2008 Free Software Foundation, Inc.
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8917
diff changeset
4 This program is free software: you can redistribute it and/or modify
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8917
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8917
diff changeset
7 (at your option) any later version.
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8917
diff changeset
14 You should have received a copy of the GNU General Public License
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8917
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <float.h>
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <string.h>
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
8528
f25a6ce872b2 Correct bitwise comparison of 'long double' numbers.
Bruno Haible <bruno@clisp.org>
parents: 8423
diff changeset
24 #include "float+.h"
f25a6ce872b2 Correct bitwise comparison of 'long double' numbers.
Bruno Haible <bruno@clisp.org>
parents: 8423
diff changeset
25
8237
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
26 #ifdef USE_LONG_DOUBLE
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
27 # define FUNC rpl_isnanl
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
28 # define DOUBLE long double
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
29 # define MAX_EXP LDBL_MAX_EXP
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
30 # define MIN_EXP LDBL_MIN_EXP
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
31 # if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
32 # define KNOWN_EXPBIT0_LOCATION
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
33 # define EXPBIT0_WORD LDBL_EXPBIT0_WORD
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
34 # define EXPBIT0_BIT LDBL_EXPBIT0_BIT
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
35 # endif
8528
f25a6ce872b2 Correct bitwise comparison of 'long double' numbers.
Bruno Haible <bruno@clisp.org>
parents: 8423
diff changeset
36 # define SIZE SIZEOF_LDBL
8237
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
37 # define L_(literal) literal##L
8650
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
38 #elif ! defined USE_FLOAT
9673
d95fe39a37f7 Fix bug introduced on 2008-01-26.
Bruno Haible <bruno@clisp.org>
parents: 9522
diff changeset
39 # define FUNC rpl_isnand
8237
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
40 # define DOUBLE double
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
41 # define MAX_EXP DBL_MAX_EXP
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
42 # define MIN_EXP DBL_MIN_EXP
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
43 # if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
44 # define KNOWN_EXPBIT0_LOCATION
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
45 # define EXPBIT0_WORD DBL_EXPBIT0_WORD
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
46 # define EXPBIT0_BIT DBL_EXPBIT0_BIT
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
47 # endif
8528
f25a6ce872b2 Correct bitwise comparison of 'long double' numbers.
Bruno Haible <bruno@clisp.org>
parents: 8423
diff changeset
48 # define SIZE SIZEOF_DBL
8237
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
49 # define L_(literal) literal
8650
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
50 #else /* defined USE_FLOAT */
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
51 # define FUNC rpl_isnanf
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
52 # define DOUBLE float
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
53 # define MAX_EXP FLT_MAX_EXP
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
54 # define MIN_EXP FLT_MIN_EXP
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
55 # if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
56 # define KNOWN_EXPBIT0_LOCATION
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
57 # define EXPBIT0_WORD FLT_EXPBIT0_WORD
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
58 # define EXPBIT0_BIT FLT_EXPBIT0_BIT
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
59 # endif
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
60 # define SIZE SIZEOF_FLT
a555b16abc8a New module 'isnanf-nolibm'.
Bruno Haible <bruno@clisp.org>
parents: 8542
diff changeset
61 # define L_(literal) literal##f
8237
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
62 #endif
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
63
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
64 #define EXP_MASK ((MAX_EXP - MIN_EXP) | 7)
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 #define NWORDS \
8237
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
67 ((sizeof (DOUBLE) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
68 typedef union { DOUBLE value; unsigned int word[NWORDS]; } memory_double;
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 int
8237
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
71 FUNC (DOUBLE x)
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 {
8237
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
73 #ifdef KNOWN_EXPBIT0_LOCATION
8917
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
74 # if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
75 /* Special CPU dependent code is needed to treat bit patterns outside the
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
76 IEEE 754 specification (such as Pseudo-NaNs, Pseudo-Infinities,
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
77 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals) as NaNs.
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
78 These bit patterns are:
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
79 - exponent = 0x0001..0x7FFF, mantissa bit 63 = 0,
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
80 - exponent = 0x0000, mantissa bit 63 = 1.
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
81 The NaN bit pattern is:
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
82 - exponent = 0x7FFF, mantissa >= 0x8000000000000001. */
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
83 memory_double m;
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
84 unsigned int exponent;
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
85
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
86 m.value = x;
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
87 exponent = (m.word[EXPBIT0_WORD] >> EXPBIT0_BIT) & EXP_MASK;
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
88 # ifdef WORDS_BIGENDIAN
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
89 /* Big endian: EXPBIT0_WORD = 0, EXPBIT0_BIT = 16. */
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
90 if (exponent == 0)
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
91 return 1 & (m.word[0] >> 15);
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
92 else if (exponent == EXP_MASK)
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
93 return (((m.word[0] ^ 0x8000U) << 16) | m.word[1] | (m.word[2] >> 16)) != 0;
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
94 else
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
95 return 1 & ~(m.word[0] >> 15);
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
96 # else
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
97 /* Little endian: EXPBIT0_WORD = 2, EXPBIT0_BIT = 0. */
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
98 if (exponent == 0)
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
99 return (m.word[1] >> 31);
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
100 else if (exponent == EXP_MASK)
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
101 return ((m.word[1] ^ 0x80000000U) | m.word[0]) != 0;
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
102 else
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
103 return (m.word[1] >> 31) ^ 1;
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
104 # endif
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
105 # else
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 /* Be careful to not do any floating-point operation on x, such as x == x,
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 because x may be a signaling NaN. */
8917
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
108 # if defined __SUNPRO_C || defined __DECC || (defined __sgi && !defined __GNUC__)
8423
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
109 /* The Sun C 5.0 compilers and the Compaq (ex-DEC) 6.4 compilers don't
8542
22c2e0092f64 Work around DEC C 6.4 compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8528
diff changeset
110 recognize the initializers as constant expressions. The latter compiler
22c2e0092f64 Work around DEC C 6.4 compiler bug.
Bruno Haible <bruno@clisp.org>
parents: 8528
diff changeset
111 also fails when constant-folding 0.0 / 0.0 even when constant-folding is
8853
65cd8f6786ed Work around bugs in the system's isnanf on IRIX and Solaris.
Bruno Haible <bruno@clisp.org>
parents: 8650
diff changeset
112 not required. The SGI MIPSpro C compiler complains about "floating-point
65cd8f6786ed Work around bugs in the system's isnanf on IRIX and Solaris.
Bruno Haible <bruno@clisp.org>
parents: 8650
diff changeset
113 operation result is out of range". */
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
114 static DOUBLE zero = L_(0.0);
8423
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
115 memory_double nan;
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
116 DOUBLE plus_inf = L_(1.0) / L_(0.0);
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
117 DOUBLE minus_inf = -L_(1.0) / L_(0.0);
9854
baba3b346ab2 Use macros NaNf, NaNd, NaNl instead of NAN.
Bruno Haible <bruno@clisp.org>
parents: 9850
diff changeset
118 nan.value = zero / zero;
8917
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
119 # else
8237
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
120 static memory_double nan = { L_(0.0) / L_(0.0) };
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
121 static DOUBLE plus_inf = L_(1.0) / L_(0.0);
c7cc3f95c8a7 Merge isnan and isnanl into a single source file.
Bruno Haible <bruno@clisp.org>
parents: 8230
diff changeset
122 static DOUBLE minus_inf = -L_(1.0) / L_(0.0);
8917
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
123 # endif
8423
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
124 {
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
125 memory_double m;
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126
8423
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
127 /* A NaN can be recognized through its exponent. But exclude +Infinity and
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
128 -Infinity, which have the same exponent. */
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
129 m.value = x;
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
130 if (((m.word[EXPBIT0_WORD] ^ nan.word[EXPBIT0_WORD])
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
131 & (EXP_MASK << EXPBIT0_BIT))
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
132 == 0)
8528
f25a6ce872b2 Correct bitwise comparison of 'long double' numbers.
Bruno Haible <bruno@clisp.org>
parents: 8423
diff changeset
133 return (memcmp (&m.value, &plus_inf, SIZE) != 0
f25a6ce872b2 Correct bitwise comparison of 'long double' numbers.
Bruno Haible <bruno@clisp.org>
parents: 8423
diff changeset
134 && memcmp (&m.value, &minus_inf, SIZE) != 0);
8423
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
135 else
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
136 return 0;
5fc4383618f0 Work around bug regarding initializers in SunPRO C and Compaq C compilers.
Bruno Haible <bruno@clisp.org>
parents: 8237
diff changeset
137 }
8917
296a84124dcd Recognize non-IEEE numbers on i386, x86_64, ia64.
Bruno Haible <bruno@clisp.org>
parents: 8853
diff changeset
138 # endif
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 #else
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 /* The configuration did not find sufficient information. Give up about
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 the signaling NaNs, handle only the quiet NaNs. */
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 if (x == x)
9521
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
143 {
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
144 # if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
145 /* Detect any special bit patterns that pass ==; see comment above. */
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
146 memory_double m1;
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
147 memory_double m2;
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
148
9522
c5f570150caf Fix bug with -0.0L in previous patch.
Eric Blake <ebb9@byu.net>
parents: 9521
diff changeset
149 memset (&m1.value, 0, SIZE);
c5f570150caf Fix bug with -0.0L in previous patch.
Eric Blake <ebb9@byu.net>
parents: 9521
diff changeset
150 memset (&m2.value, 0, SIZE);
9521
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
151 m1.value = x;
9522
c5f570150caf Fix bug with -0.0L in previous patch.
Eric Blake <ebb9@byu.net>
parents: 9521
diff changeset
152 m2.value = x + (x ? 0.0L : -0.0L);
9521
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
153 if (memcmp (&m1.value, &m2.value, SIZE) != 0)
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
154 return 1;
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
155 # endif
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
156 return 0;
9e072640eeef Detect pseudo-denormals on x86 even when cross-compiling.
Eric Blake <ebb9@byu.net>
parents: 9309
diff changeset
157 }
8230
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 else
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 return 1;
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 #endif
fc7bcbeadfee New module 'isnan-nolibm'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 }