1 ?RCS: $Id: d_castneg.U,v 3.0.1.2 1995/05/12 12:11:21 ram Exp $
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
5 ?RCS: You may redistribute only under the terms of the Artistic Licence,
6 ?RCS: as specified in the README file that comes with the distribution.
7 ?RCS: You may reuse parts of this distribution only within the terms of
8 ?RCS: that same Artistic Licence; a copy of which may be found at the root
9 ?RCS: of the source tree for dist 3.0.
11 ?RCS: $Log: d_castneg.U,v $
12 ?RCS: Revision 3.0.1.2 1995/05/12 12:11:21 ram
13 ?RCS: patch54: made sure cc and ccflags are conditional dependencies
14 ?RCS: patch54: added improved test case for Interactive Unix
16 ?RCS: Revision 3.0.1.1 1994/10/29 16:10:50 ram
17 ?RCS: patch36: don't forget to tell user about compilation failures (ADO)
18 ?RCS: patch36: declare signal handler correctly using 'signal_t' (ADO)
20 ?RCS: Revision 3.0 1993/08/18 12:05:47 ram
21 ?RCS: Baseline for dist 3.0 netwide release.
24 ?X: Can the compiler cast negative / odd floats to unsigned values.
26 ?MAKE:d_castneg castflags: cat Compile rm_try Setvar signal_t run i_stdlib
27 ?MAKE: -pick add $@ %<
29 ?S: This variable conditionally defines CASTNEG, which indicates
30 ?S: whether the C compiler can cast negative float to unsigned.
33 ?S: This variable contains a flag that precise difficulties the
34 ?S: compiler has casting odd floating values to unsigned long:
36 ?S: 1 = couldn't cast < 0
37 ?S: 2 = couldn't cast >= 0x80000000
38 ?S: 4 = couldn't cast in argument expression list
41 ?C: This symbol is defined if the C compiler can cast negative
42 ?C: numbers to unsigned longs, ints and shorts.
45 ?C: This symbol contains flags that say what difficulties the compiler
46 ?C: has casting odd floating values to unsigned long:
48 ?C: 1 = couldn't cast < 0
49 ?C: 2 = couldn't cast >= 0x80000000
50 ?C: 4 = couldn't cast in argument expression list
52 ?H:#$d_castneg CASTNEGFLOAT /**/
53 ?H:#define CASTFLAGS $castflags /**/
57 : check for ability to cast negative floats to unsigned
59 echo 'Checking whether your C compiler can cast negative float to unsigned.' >&4
66 #include <sys/types.h>
68 $signal_t blech(int s) { exit(7); }
69 $signal_t blech_in_list(int s) { exit(4); }
70 unsigned long dummy_long(unsigned long p) { return p; }
71 unsigned int dummy_int(unsigned int p) { return p; }
72 unsigned short dummy_short(unsigned short p) { return p; }
78 unsigned short ashort;
82 /* Frustrate gcc-2.7.2's optimizer which failed this test with
83 a direct f = -123. assignment. gcc-2.8.0 reportedly
84 optimized the whole file away
86 /* Store the number in a writable string for gcc to pass to
90 sscanf(str, "%lf", &f); /* f = -123.; */
92 signal(SIGFPE, blech);
93 along = (unsigned long)f;
94 aint = (unsigned int)f;
95 ashort = (unsigned short)f;
96 if (along != (unsigned long)-123)
98 if (aint != (unsigned int)-123)
100 if (ashort != (unsigned short)-123)
102 sprintf(str, "1073741824.");
103 sscanf(str, "%lf", &f); /* f = (double)0x40000000; */
106 along = (unsigned long)f;
107 if (along != 0x80000000)
111 along = (unsigned long)f;
112 if (along != 0x7fffffff)
116 along = (unsigned long)f;
117 if (along != 0x80000001)
122 ?X: The following is a test for Interactive Unix Version 4.1, which
123 ?X: has an 'improved' compiler which can correctly cast negative
124 ?X: floats in expression lists, but apparently not in argument lists.
125 ?X: Contributed by Winfried Koenig <win@incom.rhein-main.de>
127 signal(SIGFPE, blech_in_list);
128 sprintf(str, "123.");
129 sscanf(str, "%lf", &f); /* f = 123.; */
130 along = dummy_long((unsigned long)f);
131 aint = dummy_int((unsigned int)f);
132 ashort = dummy_short((unsigned short)f);
133 if (along != (unsigned long)123)
135 if (aint != (unsigned int)123)
137 if (ashort != (unsigned short)123)
144 if eval $compile_ok; then
148 echo "(I can't seem to compile the test program--assuming it can't)"
156 echo "Nope, it can't."