1 /****************************************************************
3 The author of this software is David M. Gay.
5 Copyright (C) 2005 by David M. Gay
8 Permission to use, copy, modify, and distribute this software and its
9 documentation for any purpose and without fee is hereby granted,
10 provided that the above copyright notice appear in all copies and that
11 both that the copyright notice and this permission notice and warranty
12 disclaimer appear in supporting documentation, and that the name of
13 the author or any of his current or former employers not be used in
14 advertising or publicity pertaining to distribution of the software
15 without specific, written prior permission.
17 THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
19 NO EVENT SHALL THE AUTHOR OR ANY OF HIS CURRENT OR FORMER EMPLOYERS BE
20 LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
21 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
23 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
26 ****************************************************************/
28 /* Please send bug reports to David M. Gay (dmg at acm dot org,
29 * with " at " changed at "@" and " dot " changed to "."). */
31 /* Program to compute quiet NaNs of various precisions (float, */
32 /* double, and perhaps long double) on the current system, */
33 /* provided the system uses binary IEEE (P754) arithmetic. */
34 /* Note that one system's quiet NaN may be a signaling NaN on */
35 /* another system. The IEEE arithmetic standards (P754, P854) */
36 /* do not specify how to distinguish signaling NaNs from quiet */
37 /* ones, and this detail varies across systems. The computed */
38 /* NaN values are encoded in #defines for values for an */
39 /* unsigned 32-bit integer type, called Ulong below, and */
40 /* (for long double) perhaps as unsigned short values. Once */
41 /* upon a time, there were PC compilers for Intel CPUs that */
42 /* had sizeof(long double) = 10. Are such compilers still */
52 typedef unsigned Long Ulong
;
66 #define UL (unsigned long)
84 a
.L
[0] = b
.L
[0] = 0x7f800000;
86 printf("#define f_QNAN 0x%lx\n", UL c
.L
[0]);
87 a
.L
[_0
] = b
.L
[_0
] = 0x7ff00000;
88 a
.L
[_1
] = b
.L
[_1
] = 0;
89 c
.d
= a
.d
- b
.d
; /* quiet NaN */
90 printf("#define d_QNAN0 0x%lx\n", UL c
.L
[0]);
91 printf("#define d_QNAN1 0x%lx\n", UL c
.L
[1]);
93 for(i
= 0; i
< 4; i
++)
94 printf("#define ld_QNAN%d 0xffffffff\n", i
);
95 for(i
= 0; i
< 5; i
++)
96 printf("#define ldus_QNAN%d 0xffff\n", i
);
100 c
.D
= 37; /* never executed; just defeat optimization */
103 for(i
= 0; i
< 4; i
++)
104 printf("#define ld_QNAN%d 0x%lx\n", i
, UL a
.L
[i
]);
105 for(i
= 0; i
< 5; i
++)
106 printf("#define ldus_QNAN%d 0x%x\n", i
, a
.u
[i
]);
108 #endif /* HAVE_IEEE */