This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
/\=/ does not require \ even in older awk
[metaconfig.git] / U / modified / d_longdbl.U
CommitLineData
959f3c4c
JH
1?RCS: $Id: d_longdbl.U,v $
2?RCS:
3?RCS: Copyright (c) 1998 Andy Dougherty
4?RCS:
5?RCS: You may distribute under the terms of either the GNU General Public
6?RCS: License or the Artistic License, as specified in the README file.
7?RCS:
8?RCS: $Log: d_longdbl.U,v $
9?RCS:
3db366a3
MBT
10?MAKE:d_longdbl longdblsize d_ldexpl longdblkind \
11 d_long_double_style_ieee d_long_double_style_ieee_doubledouble \
12 d_long_double_style_ieee_extended d_long_double_style_ieee_std \
13 d_long_double_style_vax: Compile Setvar Myread \
9220ceee 14 Inlibc run echo cat rm_try test doublesize i_stdlib
959f3c4c
JH
15?MAKE: -pick add $@ %<
16?S:d_longdbl:
2cb64bf6 17?S: This variable conditionally defines HAS_LONG_DOUBLE if
959f3c4c
JH
18?S: the long double type is supported.
19?S:.
6cbd82a3
MBT
20?S:d_ldexpl:
21?S: This variable conditionally defines the HAS_LDEXPL symbol, which
22?S: indicates to the C program that the ldexpl() routine is available.
23?S:.
959f3c4c
JH
24?S:longdblsize:
25?S: This variable contains the value of the LONG_DOUBLESIZE symbol, which
26?S: indicates to the C program how many bytes there are in a long double,
c4037aaf
MBT
27?S: if this system supports long doubles. Note that this is
28?S: sizeof(long double), which may include unused bytes.
959f3c4c 29?S:.
6cbd82a3
MBT
30?S:longdblkind:
31?S: This variable, if defined, encodes the type of a long double:
f01e6e62
MBT
32?S: 0 = double,
33?S: 1 = IEEE 754 128-bit little endian,
34?S: 2 = IEEE 754 128-bit big endian,
35?S: 3 = x86 80-bit little endian,
36?S: 4 = x86 80-bit big endian,
37?S: 5 = double-double 128-bit little endian,
38?S: 6 = double-double 128-bit big endian,
7253d5da
MBT
39?S: 7 = 128-bit mixed-endian double-double (64-bit LEs in BE),
40?S: 8 = 128-bit mixed-endian double-double (64-bit BEs in LE),
41?S: 9 = 128-bit PDP-style mixed-endian long doubles,
8189533f 42?S: -1 = unknown format.
6cbd82a3 43?S:.
3db366a3
MBT
44?S:d_long_double_style_ieee:
45?S: This variable conditionally defines LONG_DOUBLE_STYLE_IEEE
46?S: if the long double is any of the IEEE 754 style long doubles:
47?S: LONG_DOUBLE_STYLE_IEEE_STD, LONG_DOUBLE_STYLE_IEEE_EXTENDED,
48?S: LONG_DOUBLE_STYLE_IEEE_DOUBLEDOUBLE.
49?S:.
50?S:d_long_double_style_ieee_doubledouble:
51?S: This variable conditionally defines LONG_DOUBLE_STYLE_IEEE_DOUBLEDOUBLE
52?S: if the long double is the 128-bit IEEE 754 double-double.
53?S:.
54?S:d_long_double_style_ieee_extended:
55?S: This variable conditionally defines LONG_DOUBLE_STYLE_IEEE_EXTENDED
56?S: if the long double is the 80-bit IEEE 754 extended precision.
57?S: Note that despite the 'extended' this is less than the 'std',
80d33c47 58?S: since this is an extension of the double precision.
3db366a3
MBT
59?S:.
60?S:d_long_double_style_ieee_std:
61?S: This variable conditionally defines LONG_DOUBLE_STYLE_IEEE_STD
62?S: if the long double is the 128-bit IEEE 754.
63?S:.
64?S:d_long_double_style_vax:
65?S: This variable conditionally defines LONG_DOUBLE_STYLE_VAX
66?S: if the long double is the 128-bit VAX format H.
67?S:.
959f3c4c
JH
68?C:HAS_LONG_DOUBLE:
69?C: This symbol will be defined if the C compiler supports long
70?C: doubles.
71?C:.
72?C:LONG_DOUBLESIZE:
2cb64bf6 73?C: This symbol contains the size of a long double, so that the
959f3c4c 74?C: C preprocessor can make decisions based on it. It is only
c4037aaf
MBT
75?C: defined if the system supports long doubles. Note that this
76?C: is sizeof(long double), which may include unused bytes.
959f3c4c 77?C:.
6cbd82a3
MBT
78?C:HAS_LDEXPL:
79?C: This symbol, if defined, indicates that the ldexpl routine is
80?C: available to shift a long double floating-point number
81?C: by an integral power of 2.
82?C:.
83?C:LONG_DOUBLEKIND:
84?C: LONG_DOUBLEKIND will be one of
85?C: LONG_DOUBLE_IS_DOUBLE
86?C: LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
87?C: LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
88?C: LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN
89?C: LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN
8189533f
AC
90?C: LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE
91?C: LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE
92?C: LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE
93?C: LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE
a4bfdb57
KW
94?C: LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LITTLE_ENDIAN
95?C: LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BIG_ENDIAN
7253d5da 96?C: LONG_DOUBLE_IS_VAX_H_FLOAT
6cbd82a3
MBT
97?C: LONG_DOUBLE_IS_UNKNOWN_FORMAT
98?C: It is only defined if the system supports long doubles.
99?C:.
3db366a3
MBT
100?C:LONG_DOUBLE_STYLE_IEEE:
101?C: This symbol, if defined, indicates that the long double
102?C: is any of the IEEE 754 style long doubles:
103?C: LONG_DOUBLE_STYLE_IEEE_STD, LONG_DOUBLE_STYLE_IEEE_EXTENDED,
104?C: LONG_DOUBLE_STYLE_IEEE_DOUBLEDOUBLE.
105?C:.
106?C:LONG_DOUBLE_STYLE_IEEE_DOUBLEDOUBLE:
107?C: This symbol, if defined, indicates that the long double is
108?C: the 128-bit double-double.
109?C:.
110?C:LONG_DOUBLE_STYLE_IEEE_EXTENDED:
111?C: This symbol, if defined, indicates that the long double is
112?C: the 80-bit IEEE 754. Note that despite the 'extended' this
113?C: is less than the 'std', since this is an extension of
114?C: the double precision.
115?C:.
116?C:LONG_DOUBLE_STYLE_IEEE_STD:
117?C: This symbol, if defined, indicates that the long double is
118?C: the 128-bit IEEE 754.
119?C:.
120?C:LONG_DOUBLE_STYLE_VAX:
121?C: This symbol, if defined, indicates that the long double is
122?C: the 128-bit VAX format H.
123?C:.
6cbd82a3 124?H:#$d_ldexpl HAS_LDEXPL /**/
959f3c4c
JH
125?H:#$d_longdbl HAS_LONG_DOUBLE /**/
126?H:?LONG_DOUBLESIZE:#ifdef HAS_LONG_DOUBLE
127?H:?LONG_DOUBLESIZE:#define LONG_DOUBLESIZE $longdblsize /**/
6cbd82a3
MBT
128?H:?LONG_DOUBLESIZE:#define LONG_DOUBLEKIND $longdblkind /**/
129?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_DOUBLE 0
130?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN 1
131?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN 2
132?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN 3
133?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN 4
8189533f
AC
134?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE 5
135?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE 6
136?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE 7
137?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE 8
7253d5da 138?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_VAX_H_FLOAT 9
6cbd82a3 139?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_UNKNOWN_FORMAT -1
8189533f
AC
140?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LITTLE_ENDIAN LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE /* back-compat */
141?H:?LONG_DOUBLESIZE:#define LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BIG_ENDIAN LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE /* back-compat */
3db366a3
MBT
142?H:?LONG_DOUBLESIZE:#$d_long_double_style_ieee LONG_DOUBLE_STYLE_IEEE
143?H:?LONG_DOUBLESIZE:#$d_long_double_style_ieee_doubledouble LONG_DOUBLE_STYLE_IEEE_DOUBLEDOUBLE
144?H:?LONG_DOUBLESIZE:#$d_long_double_style_ieee_extended LONG_DOUBLE_STYLE_IEEE_EXTENDED
145?H:?LONG_DOUBLESIZE:#$d_long_double_style_ieee_std LONG_DOUBLE_STYLE_IEEE_STD
146?H:?LONG_DOUBLESIZE:#$d_long_double_style_vax LONG_DOUBLE_STYLE_VAX
959f3c4c
JH
147?H:?LONG_DOUBLESIZE:#endif
148?H:.
0065f4af 149?F:!try
6cbd82a3
MBT
150?LINT:known LONG_DOUBLE_IS_DOUBLE LONG_DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
151?LINT:known LONG_DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN LONG_DOUBLE_IS_X86_80_BIT_LITTLE_ENDIAN
152?LINT:known LONG_DOUBLE_IS_X86_80_BIT_BIG_ENDIAN LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LITTLE_ENDIAN
153?LINT:known LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BIG_ENDIAN LONG_DOUBLE_IS_UNKNOWN_FORMAT
8189533f
AC
154?LINT:known LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_LE
155?LINT:known LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_BE
156?LINT:known LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_LE_BE
157?LINT:known LONG_DOUBLE_IS_DOUBLEDOUBLE_128_BIT_BE_LE
7253d5da 158?LINT:known LONG_DOUBLE_IS_VAX_H_FLOAT
959f3c4c 159?LINT:set d_longdbl
6cbd82a3 160?LINT:set d_ldexpl
959f3c4c 161: check for long doubles
bb108574 162echo " " >&4
840deeaa 163echo "Checking to see if you have long double..." >&4
a38738d1
JH
164echo 'int main() { long double x = 7.0; }' > try.c
165set try
166if eval $compile; then
959f3c4c 167 val="$define"
bb108574 168 echo "You have long double." >&4
959f3c4c
JH
169else
170 val="$undef"
bb108574 171 echo "You do not have long double." >&4
959f3c4c 172fi
2cb64bf6 173$rm_try
959f3c4c
JH
174set d_longdbl
175eval $setvar
176
6cbd82a3
MBT
177: see if ldexpl exists
178set ldexpl d_ldexpl
179eval $inlibc
180
959f3c4c
JH
181@if LONG_DOUBLESIZE || longdblsize
182: check for length of long double
183?X: Check only if d_longdbl and if longdblsize is not already set.
184case "${d_longdbl}${longdblsize}" in
185$define)
bb108574 186 echo " " >&4
0fdea05a 187 echo "Checking to see how big your long doubles are..." >&4
959f3c4c
JH
188 $cat >try.c <<'EOCP'
189#include <stdio.h>
190int main()
191{
192 printf("%d\n", sizeof(long double));
193}
194EOCP
195 set try
196?X: Don't use compile_ok because some compilers warn you that they have
197?X: 'long double' as just 'double'.
a38738d1 198 set try
959f3c4c 199 if eval $compile; then
0f00356b 200 longdblsize=`$run ./try`
bb108574 201 echo "Your long doubles are $longdblsize bytes long." >&4
959f3c4c
JH
202 else
203 dflt='8'
bb108574 204 echo " " >&4
959f3c4c
JH
205 echo "(I can't seem to compile the test program. Guessing...)" >&4
206 rp="What is the size of a long double (in bytes)?"
207 . ./myread
208 longdblsize="$ans"
209 fi
210 if $test "X$doublesize" = "X$longdblsize"; then
bb108574
KW
211 echo "That isn't any different from an ordinary double." >&4
212 echo "I'll keep your setting anyway, but you may see some" >&4
213 echo "harmless compilation warnings." >&4
2cb64bf6 214 fi
959f3c4c
JH
215 ;;
216esac
2cb64bf6 217$rm_try
959f3c4c
JH
218@end
219
6cbd82a3
MBT
220$echo "Checking the kind of long doubles you have..." >&4
221case "$d_longdbl" in
222define)
223$cat <<EOP >try.c
6cbd82a3
MBT
224#$i_stdlib I_STDLIB
225#define LONGDBLSIZE $longdblsize
63a4f1f4 226#define DOUBLESIZE $doublesize
6cbd82a3 227#include <float.h>
6cbd82a3
MBT
228#ifdef I_STDLIB
229#include <stdlib.h>
230#endif
231#include <stdio.h>
232static const long double d = -0.1L;
233int main() {
234 unsigned const char* b = (unsigned const char*)(&d);
63a4f1f4
MBT
235#if DOUBLESIZE == LONGDBLSIZE
236 printf("0\n"); /* if it floats like double */
237 exit(0);
238#endif
239#if (LDBL_MANT_DIG == 113 || FLT128_MANT_DIG == 113) && LONGDBLSIZE == 16
6cbd82a3
MBT
240 if (b[0] == 0x9A && b[1] == 0x99 && b[15] == 0xBF) {
241 /* IEEE 754 128-bit little-endian */
242 printf("1\n");
243 exit(0);
244 }
245 if (b[0] == 0xBF && b[14] == 0x99 && b[15] == 0x9A) {
246 /* IEEE 128-bit big-endian, e.g. solaris sparc */
247 printf("2\n");
248 exit(0);
249 }
250#endif
63a4f1f4 251/* For alignment 32-bit platforms have the 80 bits in 12 bytes,
5f2a9443
AC
252 * while 64-bits platforms have it in 16 bytes. The trailing bytes
253 * cannot be trusted. */
6cbd82a3 254#if LDBL_MANT_DIG == 64 && (LONGDBLSIZE == 16 || LONGDBLSIZE == 12)
5f2a9443 255 if (b[0] == 0xCD && b[9] == 0xBF) {
6cbd82a3
MBT
256 /* x86 80-bit little-endian, sizeof 12 (ILP32, Solaris x86)
257 * or 16 (LP64, Linux and OS X), 4 or 6 bytes of padding.
258 * Also known as "extended precision". */
259 printf("3\n");
260 exit(0);
261 }
5f2a9443
AC
262 if (b[0] == 0xBF && b[9] == 0xCD) {
263 /* Is there ever big-endian 80-bit, really?
264 *
265 * The Motorola 68881 had another "extended precision" format:
266 * sign:1 exp:15 zero:16 integer:1 mantissa:63
267 * for total of 96 bits of bytes. The zero bits were unused.
f09dc586
MB
268 * See "M68000 FAMILY PROGRAMMER'S REFERENCE MANUAL" for more details.
269 * If it ever becomes relevant, this format should be allocated a
270 * new doublekind code since it is quite different from the Intel x87.
5f2a9443 271 */
6cbd82a3
MBT
272 printf("4\n");
273 exit(0);
274 }
275#endif
63a4f1f4
MBT
276#if (LDBL_MANT_DIG == 106 || LDBL_MANT_DIG == 107) && LONGDBLSIZE == 16
277 /* software "double double", the 106 is 53+53.
278 * but irix thinks it is 107. */
6cbd82a3 279 if (b[0] == 0x9A && b[7] == 0x3C && b[8] == 0x9A && b[15] == 0xBF) {
5f2a9443
AC
280 /* double double 128-bit fully little-endian,
281 * little-endian doubles in little-endian order,
6cbd82a3
MBT
282 * 9a 99 99 99 99 99 59 3c 9a 99 99 99 99 99 b9 bf */
283 printf("5\n");
284 exit(0);
285 }
286 if (b[0] == 0xBF && b[7] == 0x9A && b[8] == 0x3C && b[15] == 0x9A) {
5f2a9443
AC
287 /* double double 128-bit fully big-endian,
288 * big-endian doubles in big-endian order,
289 * e.g. PPC/Power and MIPS:
6cbd82a3
MBT
290 * bf b9 99 99 99 99 99 9a 3c 59 99 99 99 99 99 9a */
291 printf("6\n");
292 exit(0);
293 }
5f2a9443
AC
294 if (b[0] == 0x9A && b[7] == 0xBF && b[8] == 0x9A && b[15] == 0x3C) {
295 /* double double 128-bit mixed endian.
296 * little-endian doubles in big-endian order,
297 * e.g. ppc64el,
298 * 9a 99 99 99 99 99 b9 bf 9a 99 99 99 99 99 59 3c */
299 printf("7\n");
300 exit(0);
301 }
302 if (b[0] == 0x3C && b[7] == 0x9A && b[8] == 0xBF && b[15] == 0x9A) {
303 /* double double 128-bit mixed endian,
304 * big-endian doubles in little-endian order,
305 * 3c 59 99 99 99 99 99 9a bf b9 99 99 99 99 99 9a */
306 printf("8\n");
307 exit(0);
308 }
6cbd82a3 309#endif
7253d5da
MBT
310/* We are largely making this up because it may well be
311 * that the VAX format H was never made available to C,
312 * only to Fortran. */
313#if LONGDBLSIZE == 16 && defined(__vax__)
314 if (b[0] == 0xFD && b[15] == 0x99) {
315 /* VAX format H, PDP-11 mixed endian. */
316 printf("9\n");
317 exit(0);
318 }
319#endif
6cbd82a3
MBT
320 printf("-1\n"); /* unknown */
321 exit(0);
322}
323EOP
324set try
325if eval $compile; then
326 longdblkind=`$run ./try`
327else
328 longdblkind=-1
329fi
330;;
331*) longdblkind=0 ;;
332esac
333case "$longdblkind" in
3340) echo "Your long doubles are doubles." >&4 ;;
3351) echo "You have IEEE 754 128-bit little endian long doubles." >&4 ;;
3362) echo "You have IEEE 754 128-bit big endian long doubles." >&4 ;;
bb108574
KW
3373) echo "You have x86 80-bit little endian long doubles." >&4 ;;
3384) echo "You have x86 80-bit big endian long doubles." >&4 ;;
3395) echo "You have 128-bit fully little-endian double-double long doubles (64-bit LEs in LE)." >&4 ;;
3406) echo "You have 128-bit fully big-endian double-double long doubles (64-bit BEs in BE)." >&4 ;;
3417) echo "You have 128-bit mixed-endian double-double long doubles (64-bit LEs in BE)." >&4 ;;
3428) echo "You have 128-bit mixed-endian double-double long doubles (64-bit BEs in LE)." >&4 ;;
3439) echo "You have 128-bit PDP-style mixed-endian long doubles (VAX format H)." >&4 ;;
6cbd82a3
MBT
344*) echo "Cannot figure out your long double." >&4 ;;
345esac
3db366a3
MBT
346d_long_double_style_ieee=$undef
347d_long_double_style_ieee_std=$undef
348d_long_double_style_ieee_extended=$undef
349d_long_double_style_ieee_doubledouble=$undef
350d_long_double_style_vax=$undef
351case "$longdblkind" in
3521|2|3|4|5|6|7|8) d_long_double_style_ieee=$define ;;
353esac
354case "$longdblkind" in
3551|2) d_long_double_style_ieee_std=$define ;;
356esac
357case "$longdblkind" in
3583|4) d_long_double_style_ieee_extended=$define ;;
359esac
360case "$longdblkind" in
3615|6|7|8) d_long_double_style_ieee_doubledouble=$define ;;
362esac
363case "$longdblkind" in
3649) d_long_double_style_vax=$define ;;
365esac
6cbd82a3
MBT
366$rm_try
367