1 /* $NetBSD: arithchk.c,v 1.4 2012/06/24 15:26:03 christos Exp $ */
3 /****************************************************************
4 Copyright (C) 1997, 1998 Lucent Technologies
7 Permission to use, copy, modify, and distribute this software and
8 its documentation for any purpose and without fee is hereby
9 granted, provided that the above copyright notice appear in all
10 copies and that both that the copyright notice and this
11 permission notice and warranty disclaimer appear in supporting
12 documentation, and that the name of Lucent or any of its entities
13 not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
19 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
20 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
22 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
23 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25 ****************************************************************/
27 /* Try to deduce arith.h from arithmetic properties. */
39 IEEE_LITTLE_ENDIAN
= { "IEEE_LITTLE_ENDIAN", 1 },
40 IEEE_BIG_ENDIAN
= { "IEEE_BIG_ENDIAN", 2 },
57 if (sizeof(x
) > 2*(sizeof(double) + sizeof(long)))
61 if (u
.L
[0] == 1117925532 && u
.L
[1] == -448790528)
62 return &IEEE_BIG_ENDIAN
;
63 if (u
.L
[1] == 1117925532 && u
.L
[0] == -448790528)
64 return &IEEE_LITTLE_ENDIAN
;
65 if (u
.L
[0] == -2065213935 && u
.L
[1] == 10752)
67 if (u
.L
[0] == 1267827943 && u
.L
[1] == 704643072)
84 if (sizeof(x
) > 2*(sizeof(double) + sizeof(int)))
88 if (u
.L
[0] == 1117925532 && u
.L
[1] == -448790528)
89 return &IEEE_BIG_ENDIAN
;
90 if (u
.L
[1] == 1117925532 && u
.L
[0] == -448790528)
91 return &IEEE_LITTLE_ENDIAN
;
92 if (u
.L
[0] == -2065213935 && u
.L
[1] == 10752)
94 if (u
.L
[0] == 1267827943 && u
.L
[1] == 704643072)
99 char *emptyfmt
= ""; /* avoid possible warning message with printf("") */
110 /* Cray1 = 4617762693716115456 -- without overflow on non-Crays */
111 Cray1
= printf(emptyfmt
) < 0 ? 0 : 4617762;
112 if (printf(emptyfmt
, Cray1
) >= 0)
113 Cray1
= 1000000*Cray1
+ 693716;
114 if (printf(emptyfmt
, Cray1
) >= 0)
115 Cray1
= 1000000*Cray1
+ 115456;
130 for(i
= 155;; b
*= b
, i
>>= 1) {
148 #ifdef WRITE_ARITH_H /* for Symantec's buggy "make" */
149 f
= fopen("arith.h", "w");
151 printf("Cannot open arith.h\n");
158 if (sizeof(double) == 2*sizeof(long))
160 else if (sizeof(double) == 2*sizeof(int)) {
164 else if (sizeof(double) == sizeof(long))
167 fprintf(f
, "#define %s\n#define Arith_Kind_ASL %d\n",
170 fprintf(f
, "#define Long int\n#define Intcast (int)(long)\n");
172 fprintf(f
, "#define Double_Align\n");
173 if (sizeof(char*) == 8)
174 fprintf(f
, "#define X64_bit_pointers\n");
176 if (sizeof(long long) < 8)
178 fprintf(f
, "#define NO_LONG_LONG\n");
179 if (a
->kind
<= 2 && fzcheck())
180 fprintf(f
, "#define Sudden_Underflow\n");
186 fprintf(f
, "/* Unknown arithmetic */\n");