This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add the files from dist/meta to perl's repo
[metaconfig.git] / dist / U / d_castneg.U
CommitLineData
d8875586
MBT
1?RCS: $Id: d_castneg.U 1 2006-08-24 12:32:52Z rmanfredi $
2?RCS:
3?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
4?RCS:
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 4.0.
10?RCS:
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
15?RCS:
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)
19?RCS:
20?RCS: Revision 3.0 1993/08/18 12:05:47 ram
21?RCS: Baseline for dist 3.0 netwide release.
22?RCS:
23?X:
24?X: Can the compiler cast negative / odd floats to unsigned values.
25?X:
26?MAKE:d_castneg castflags: cat +cc +ccflags rm Setvar signal_t
27?MAKE: -pick add $@ %<
28?S:d_castneg:
29?S: This variable conditionally defines CASTNEG, which indicates
30?S: wether the C compiler can cast negative float to unsigned.
31?S:.
32?S:castflags:
33?S: This variable contains a flag that precise difficulties the
34?S: compiler has casting odd floating values to unsigned long:
35?S: 0 = ok
36?S: 1 = couldn't cast < 0
37?S: 2 = couldn't cast >= 0x80000000
38?S: 4 = couldn't cast in argument expression list
39?S:.
40?C:CASTNEGFLOAT:
41?C: This symbol is defined if the C compiler can cast negative
42?C: numbers to unsigned longs, ints and shorts.
43?C:.
44?C:CASTFLAGS:
45?C: This symbol contains flags that say what difficulties the compiler
46?C: has casting odd floating values to unsigned long:
47?C: 0 = ok
48?C: 1 = couldn't cast < 0
49?C: 2 = couldn't cast >= 0x80000000
50?C: 4 = couldn't cast in argument expression list
51?C:.
52?H:#$d_castneg CASTNEGFLOAT /**/
53?H:#define CASTFLAGS $castflags /**/
54?H:.
55?F:!try
56?LINT:set d_castneg
57: check for ability to cast negative floats to unsigned
58echo " "
59echo 'Checking whether your C compiler can cast negative float to unsigned.' >&4
60$cat >try.c <<EOCP
61#include <sys/types.h>
62#include <signal.h>
63$signal_t blech() { exit(7); }
64$signal_t blech_in_list() { exit(4); }
65unsigned long dummy_long(p) unsigned long p; { return p; }
66unsigned int dummy_int(p) unsigned int p; { return p; }
67unsigned short dummy_short(p) unsigned short p; { return p; }
68int main()
69{
70 double f = -123.;
71 unsigned long along;
72 unsigned int aint;
73 unsigned short ashort;
74 int result = 0;
75
76 signal(SIGFPE, blech);
77 along = (unsigned long)f;
78 aint = (unsigned int)f;
79 ashort = (unsigned short)f;
80 if (along != (unsigned long)-123)
81 result |= 1;
82 if (aint != (unsigned int)-123)
83 result |= 1;
84 if (ashort != (unsigned short)-123)
85 result |= 1;
86 f = (double)0x40000000;
87 f = f + f;
88 along = 0;
89 along = (unsigned long)f;
90 if (along != 0x80000000)
91 result |= 2;
92 f -= 1.;
93 along = 0;
94 along = (unsigned long)f;
95 if (along != 0x7fffffff)
96 result |= 1;
97 f += 2.;
98 along = 0;
99 along = (unsigned long)f;
100 if (along != 0x80000001)
101 result |= 2;
102 if (result)
103 exit(result);
104?X:
105?X: The following is a test for Interactive Unix Version 4.1, which
106?X: has an 'improved' compiler which can correctly cast negative
107?X: floats in expression lists, but apparently not in argument lists.
108?X: Contributed by Winfried Koenig <win@incom.rhein-main.de>
109?X:
110 signal(SIGFPE, blech_in_list);
111 f = 123.;
112 along = dummy_long((unsigned long)f);
113 aint = dummy_int((unsigned int)f);
114 ashort = dummy_short((unsigned short)f);
115 if (along != (unsigned long)123)
116 result |= 4;
117 if (aint != (unsigned int)123)
118 result |= 4;
119 if (ashort != (unsigned short)123)
120 result |= 4;
121 exit(result);
122
123}
124EOCP
125if $cc $ccflags -o try try.c >/dev/null 2>&1; then
126 ./try
127 castflags=$?
128else
129 echo "(I can't seem to compile the test program--assuming it can't)"
130 castflags=7
131fi
132case "$castflags" in
1330) val="$define"
134 echo "Yup, it can."
135 ;;
136*) val="$undef"
137 echo "Nope, it can't."
138 ;;
139esac
140set d_castneg
141eval $setvar
142$rm -f try.*
143