This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix .gitignore: only ignore 'perl' in root of repo, not U/perl subdir
[metaconfig.git] / U / perl / longdblfio.U
CommitLineData
cd276bb8
JH
1?RCS: $Id$
2?RCS:
e4c74dcb 3?RCS: Copyright (c) 1999-2016 Jarkko Hietaniemi
cd276bb8
JH
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:
3bb42500
JH
8?MAKE:d_PRIfldbl sPRIfldbl d_PRIgldbl d_PRIFUldbl sPRIGUldbl d_PRIEUldbl \
9 sPRIgldbl d_PRIeldbl sPRIeldbl sPRIFUldbl d_PRIGUldbl sPRIEUldbl \
3db366a3
MBT
10 d_SCNfldbl d_double_style_vax d_double_style_ieee \
11 d_double_style_ibm d_double_style_cray d_double_has_subnormals \
12 d_double_has_inf d_double_has_nan d_double_has_negative_zero \
63a4f1f4
MBT
13 sSCNfldbl doublekind: \
14 d_longdbl longdblsize doublesize uselongdouble test echo cat rm_try \
15 Setvar Compile run i_stdlib osname gccversion ccflags
cd276bb8 16?MAKE: -pick add $@ %<
63a4f1f4
MBT
17?S:doublekind:
18?S: This variable, if defined, encodes the type of a double:
b7f73904
AC
19?S: 1 = IEEE 754 32-bit little endian,
20?S: 2 = IEEE 754 32-bit big endian,
21?S: 3 = IEEE 754 64-bit little endian,
22?S: 4 = IEEE 754 64-bit big endian,
23?S: 5 = IEEE 754 128-bit little endian,
24?S: 6 = IEEE 754 128-bit big endian,
25?S: 7 = IEEE 754 64-bit mixed endian le-be,
26?S: 8 = IEEE 754 64-bit mixed endian be-le,
e4c74dcb
MBT
27?S: 9 = VAX 32bit little endian F float format
28?S: 10 = VAX 64bit little endian D float format
29?S: 11 = VAX 64bit little endian G float format
48315511
MBT
30?S: 12 = IBM 32bit format
31?S: 13 = IBM 64bit format
32?S: 14 = Cray 64bit format
63a4f1f4
MBT
33?S: -1 = unknown format.
34?S:.
cd276bb8 35?S:d_PRIfldbl:
6afacc59 36?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
4dd7201d 37?S: indicates that stdio has a symbol to print long doubles.
cd276bb8
JH
38?S:.
39?S:d_PRIgldbl:
6afacc59 40?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
4dd7201d 41?S: indicates that stdio has a symbol to print long doubles.
cd276bb8
JH
42?S:.
43?S:d_PRIeldbl:
6afacc59 44?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
4dd7201d 45?S: indicates that stdio has a symbol to print long doubles.
cd276bb8 46?S:.
3bb42500 47?S:d_PRIFUldbl:
6afacc59 48?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
4dd7201d 49?S: indicates that stdio has a symbol to print long doubles.
3bb42500
JH
50?S: The 'U' in the name is to separate this from d_PRIfldbl so that even
51?S: case-blind systems can see the difference.
cd276bb8 52?S:.
3bb42500 53?S:d_PRIGUldbl:
6afacc59 54?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
4dd7201d 55?S: indicates that stdio has a symbol to print long doubles.
3bb42500
JH
56?S: The 'U' in the name is to separate this from d_PRIgldbl so that even
57?S: case-blind systems can see the difference.
cd276bb8 58?S:.
3bb42500 59?S:d_PRIEUldbl:
6afacc59 60?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
4dd7201d 61?S: indicates that stdio has a symbol to print long doubles.
3bb42500
JH
62?S: The 'U' in the name is to separate this from d_PRIeldbl so that even
63?S: case-blind systems can see the difference.
cd276bb8 64?S:.
6afacc59
JH
65?S:d_SCNfldbl:
66?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
4dd7201d 67?S: indicates that stdio has a symbol to scan long doubles.
6afacc59 68?S:.
cd276bb8
JH
69?S:sPRIfldbl:
70?S: This variable, if defined, contains the string used by stdio to
71?S: format long doubles (format 'f') for output.
72?S:.
73?S:sPRIgldbl:
74?S: This variable, if defined, contains the string used by stdio to
75?S: format long doubles (format 'g') for output.
76?S:.
77?S:sPRIeldbl:
78?S: This variable, if defined, contains the string used by stdio to
79?S: format long doubles (format 'e') for output.
80?S:.
3bb42500 81?S:sPRIFUldbl:
cd276bb8
JH
82?S: This variable, if defined, contains the string used by stdio to
83?S: format long doubles (format 'F') for output.
3bb42500
JH
84?S: The 'U' in the name is to separate this from sPRIfldbl so that even
85?S: case-blind systems can see the difference.
cd276bb8 86?S:.
3bb42500 87?S:sPRIGUldbl:
cd276bb8
JH
88?S: This variable, if defined, contains the string used by stdio to
89?S: format long doubles (format 'G') for output.
3bb42500
JH
90?S: The 'U' in the name is to separate this from sPRIgldbl so that even
91?S: case-blind systems can see the difference.
cd276bb8 92?S:.
3bb42500 93?S:sPRIEUldbl:
cd276bb8
JH
94?S: This variable, if defined, contains the string used by stdio to
95?S: format long doubles (format 'E') for output.
3bb42500
JH
96?S: The 'U' in the name is to separate this from sPRIeldbl so that even
97?S: case-blind systems can see the difference.
cd276bb8 98?S:.
6afacc59
JH
99?S:sSCNfldbl:
100?S: This variable, if defined, contains the string used by stdio to
101?S: format long doubles (format 'f') for input.
102?S:.
3db366a3
MBT
103?S:d_double_has_inf:
104?S: This variable conditionally defines the symbol DOUBLE_HAS_INF
105?S: which indicates that the double type has an infinity.
106?S:.
107?S:d_double_has_nan:
1f2a00f8 108?S: This variable conditionally defines the symbol DOUBLE_HAS_NAN
3db366a3
MBT
109?S: which indicates that the double type has a not-a-number.
110?S:.
111?S:d_double_has_negative_zero:
112?S: This variable conditionally defines the symbol DOUBLE_HAS_NEGATIVE_ZERO
113?S: which indicates that the double type has a negative zero.
114?S:.
115?S:d_double_has_subnormals:
116?S: This variable conditionally defines the symbol DOUBLE_HAS_SUBNORMALS
117?S: which indicates that the double type has subnormals (denormals).
118?S:.
119?S:d_double_style_cray:
120?S: This variable conditionally defines the symbol DOUBLE_STYLE_CRAY
121?S: which indicates that the double is the 64-bit CRAY mainframe format.
122?S:.
123?S:d_double_style_ibm:
124?S: This variable conditionally defines the symbol DOUBLE_STYLE_IBM,
125?S: which indicates that the double is the 64-bit IBM mainframe format.
126?S:.
127?S:d_double_style_ieee:
128?S: This variable conditionally defines the symbol DOUBLE_STYLE_IEEE,
129?S: which indicates that the double is the 64-bit IEEE 754.
130?S:.
131?S:d_double_style_vax:
132?S: This variable conditionally defines the symbol DOUBLE_STYLE_VAX,
133?S: which indicates that the double is the 64-bit VAX format D or G.
134?S:.
cd276bb8
JH
135?C:PERL_PRIfldbl:
136?C: This symbol, if defined, contains the string used by stdio to
137?C: format long doubles (format 'f') for output.
138?C:.
139?C:PERL_PRIgldbl:
140?C: This symbol, if defined, contains the string used by stdio to
141?C: format long doubles (format 'g') for output.
142?C:.
143?C:PERL_PRIeldbl:
144?C: This symbol, if defined, contains the string used by stdio to
145?C: format long doubles (format 'e') for output.
146?C:.
147?C:PERL_PRIFldbl:
148?C: This symbol, if defined, contains the string used by stdio to
149?C: format long doubles (format 'f') for output.
150?C:.
151?C:PERL_PRIGldbl:
152?C: This symbol, if defined, contains the string used by stdio to
153?C: format long doubles (format 'g') for output.
154?C:.
155?C:PERL_PRIEldbl:
156?C: This symbol, if defined, contains the string used by stdio to
157?C: format long doubles (format 'e') for output.
158?C:.
6afacc59
JH
159?C:PERL_SCNfldbl:
160?C: This symbol, if defined, contains the string used by stdio to
161?C: format long doubles (format 'f') for input.
162?C:.
0c7f0563
MBT
163?C:DOUBLEKIND:
164?C: DOUBLEKIND will be one of
165?C: DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN
166?C: DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN
167?C: DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN
168?C: DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN
169?C: DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
170?C: DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
171?C: DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE
172?C: DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE
e4c74dcb
MBT
173?C: DOUBLE_IS_VAX_F_FLOAT
174?C: DOUBLE_IS_VAX_D_FLOAT
175?C: DOUBLE_IS_VAX_G_FLOAT
48315511
MBT
176?C: DOUBLE_IS_IBM_SINGLE_32_BIT
177?C: DOUBLE_IS_IBM_DOUBLE_64_BIT
178?C: DOUBLE_IS_CRAY_SINGLE_64_BIT
0c7f0563
MBT
179?C: DOUBLE_IS_UNKNOWN_FORMAT
180?C:.
87f28464
MBT
181?C:DOUBLE_HAS_INF:
182?C: This symbol, if defined, indicates that the double has
183?C: the infinity.
184?C:.
185?C:DOUBLE_HAS_NAN:
186?C: This symbol, if defined, indicates that the double has
187?C: the not-a-number.
188?C:.
189?C:DOUBLE_HAS_NEGATIVE_ZERO:
190?C: This symbol, if defined, indicates that the double has
191?C: the negative_zero.
192?C:.
193?C:DOUBLE_HAS_SUBNORMALS:
194?C: This symbol, if defined, indicates that the double has
195?C: the subnormals (denormals).
196?C:.
197?C:DOUBLE_STYLE_CRAY:
198?C: This symbol, if defined, indicates that the double is
199?C: the 64-bit CRAY mainframe format.
200?C:.
201?C:DOUBLE_STYLE_IBM:
202?C: This symbol, if defined, indicates that the double is
203?C: the 64-bit IBM mainframe format.
204?C:.
205?C:DOUBLE_STYLE_IEEE:
206?C: This symbol, if defined, indicates that the double is
207?C: the 64-bit IEEE 754.
208?C:.
209?C:DOUBLE_STYLE_VAX:
210?C: This symbol, if defined, indicates that the double is
211?C: the 64-bit VAX format D or G.
212?C:.
0c7f0563
MBT
213?LINT:known DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN
214?LINT:known DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN
215?LINT:known DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN
216?LINT:known DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN
217?LINT:known DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
218?LINT:known DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
219?LINT:known DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE
220?LINT:known DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE
e4c74dcb
MBT
221?LINT:known DOUBLE_IS_VAX_F_FLOAT
222?LINT:known DOUBLE_IS_VAX_D_FLOAT
223?LINT:known DOUBLE_IS_VAX_G_FLOAT
48315511
MBT
224?LINT:known DOUBLE_IS_IBM_SINGLE_32_BIT
225?LINT:known DOUBLE_IS_IBM_DOUBLE_64_BIT
226?LINT:known DOUBLE_IS_CRAY_SINGLE_64_BIT
0c7f0563
MBT
227?LINT:known DOUBLE_IS_UNKNOWN_FORMAT
228?H:#define DOUBLEKIND $doublekind /**/
229?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN 1
230?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN 2
231?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN 3
232?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN 4
233?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN 5
234?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN 6
235?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE 7
236?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE 8
e4c74dcb
MBT
237?H:?DOUBLEKIND:#define DOUBLE_IS_VAX_F_FLOAT 9
238?H:?DOUBLEKIND:#define DOUBLE_IS_VAX_D_FLOAT 10
239?H:?DOUBLEKIND:#define DOUBLE_IS_VAX_G_FLOAT 11
48315511
MBT
240?H:?DOUBLEKIND:#define DOUBLE_IS_IBM_SINGLE_32_BIT 12
241?H:?DOUBLEKIND:#define DOUBLE_IS_IBM_DOUBLE_64_BIT 13
242?H:?DOUBLEKIND:#define DOUBLE_IS_CRAY_SINGLE_64_BIT 14
0c7f0563 243?H:?DOUBLEKIND:#define DOUBLE_IS_UNKNOWN_FORMAT -1
cd276bb8
JH
244?H:#$d_PRIfldbl PERL_PRIfldbl $sPRIfldbl /**/
245?H:#$d_PRIgldbl PERL_PRIgldbl $sPRIgldbl /**/
246?H:#$d_PRIeldbl PERL_PRIeldbl $sPRIeldbl /**/
3bb42500
JH
247?H:#$d_PRIFUldbl PERL_PRIFldbl $sPRIFUldbl /**/
248?H:#$d_PRIGUldbl PERL_PRIGldbl $sPRIGUldbl /**/
249?H:#$d_PRIEUldbl PERL_PRIEldbl $sPRIEUldbl /**/
6afacc59 250?H:#$d_SCNfldbl PERL_SCNfldbl $sSCNfldbl /**/
87f28464
MBT
251?H:#$d_double_has_inf DOUBLE_HAS_INF
252?H:#$d_double_has_nan DOUBLE_HAS_NAN
253?H:#$d_double_has_negative_zero DOUBLE_HAS_NEGATIVE_ZERO
254?H:#$d_double_has_subnormals DOUBLE_HAS_SUBNORMALS
255?H:#$d_double_style_cray DOUBLE_STYLE_CRAY
256?H:#$d_double_style_ibm DOUBLE_STYLE_IBM
257?H:#$d_double_style_ieee DOUBLE_STYLE_IEEE
258?H:#$d_double_style_vax DOUBLE_STYLE_VAX
cd276bb8 259?H:.
63a4f1f4 260?T:yyy message saveccflags
0065f4af 261?F:!try
63a4f1f4
MBT
262?LINT:change ccflags
263?LINT:change uselongdouble
264: Check what kind of doubles your system has
265$echo "Checking the kind of doubles you have..." >&4
266$cat >try.c <<EOP
267#$i_stdlib I_STDLIB
268#define DOUBLESIZE $doublesize
269#ifdef I_STDLIB
270#include <stdlib.h>
271#endif
272#include <stdio.h>
273static const double d = -0.1;
274int main() {
275 unsigned const char* b = (unsigned const char*)(&d);
276#if DOUBLESIZE == 4
277 if (b[0] == 0xCD && b[3] == 0xBD) {
278 /* IEEE 754 32-bit little-endian */
279 printf("1\n");
280 exit(0);
281 }
282 if (b[0] == 0xBD && b[3] == 0xCD) {
283 /* IEEE 754 32-bit big-endian */
284 printf("2\n");
285 exit(0);
286 }
e4c74dcb 287 if (b[0] == 0xCC && b[3] == 0xCC) {
7253d5da 288 /* VAX format F, 32-bit PDP-style mixed endian. */
e4c74dcb
MBT
289 printf("9\n");
290 exit(0);
291 }
48315511
MBT
292 if (b[0] == 0xC0 && b[3] == 0x9A) {
293 /* IBM single 32-bit */
294 printf("12\n");
295 exit(0);
296 }
63a4f1f4
MBT
297#endif
298#if DOUBLESIZE == 8
299 if (b[0] == 0x9A && b[7] == 0xBF) {
300 /* IEEE 754 64-bit little-endian */
301 printf("3\n");
302 exit(0);
303 }
304 if (b[0] == 0xBF && b[7] == 0x9A) {
305 /* IEEE 754 64-bit big-endian */
306 printf("4\n");
307 exit(0);
308 }
309 if (b[0] == 0x99 && b[3] == 0xBF && b[4] == 0x9A && b[7] == 0x99) {
310 /* ARM mixed endian: two little-endian 32-bit floats, in big endian order:
311 * 4 5 6 7 0 1 2 3 (MSB = 7, LSB = 0)
312 * 99 99 b9 bf 9a 99 99 99 */
313 printf("7\n");
314 exit(0);
315 }
316 if (b[0] == 0x99 && b[3] == 0x9A && b[4] == 0xBF && b[7] == 0x99) {
317 /* The opposite of case 7, mixed endian: two big-endian 32-bit floats,
318 * in little endian order: 3 2 1 0 7 6 5 4 (MSB = 7, LSB = 0)
319 * 99 99 99 9a bf b9 99 99 */
320 printf("8\n");
321 exit(0);
322 }
e4c74dcb 323 if (b[0] == 0xCC && b[7] == 0xCC) {
7253d5da 324 /* VAX format D, 64-bit PDP-style mixed endian. */
e4c74dcb
MBT
325 printf("10\n");
326 exit(0);
327 }
328 if (b[0] == 0xD9 && b[7] == 0x99) {
7253d5da 329 /* VAX format G, 64-bit PDP-style mixed endian. */
e4c74dcb
MBT
330 printf("11\n");
331 exit(0);
332 }
48315511
MBT
333 if (b[0] == 0xC0 && b[7] == 0x9A) {
334 /* IBM double 64-bit */
335 printf("13\n");
336 exit(0);
337 }
338 if (b[0] == 0xBF && b[7] == 0xCD) {
339 /* CRAY single 64-bit */
340 printf("14\n");
341 exit(0);
342 }
63a4f1f4
MBT
343#endif
344#if DOUBLESIZE == 16
345 if (b[0] == 0x9A && b[15] == 0xBF) {
346 /* IEEE 754 128-bit little-endian */
347 printf("5\n");
348 exit(0);
349 }
350 if (b[0] == 0xBF && b[15] == 0x9A) {
351 /* IEEE 754 128-bit big-endian */
352 printf("6\n");
353 exit(0);
354 }
355#endif
e4c74dcb 356 /* Then there are old mainframe/miniframe formats like IBM and CRAY.
63a4f1f4
MBT
357 * Whether those environments can still build Perl is debatable. */
358 printf("-1\n"); /* unknown */
359 exit(0);
360}
361EOP
362set try
363if eval $compile; then
364 doublekind=`$run ./try`
365else
366 doublekind=-1
367fi
368case "$doublekind" in
3691) echo "You have IEEE 754 32-bit little endian doubles." >&4 ;;
3702) echo "You have IEEE 754 32-bit big endian doubles." >&4 ;;
3713) echo "You have IEEE 754 64-bit little endian doubles." >&4 ;;
3724) echo "You have IEEE 754 64-bit big endian doubles." >&4 ;;
3735) echo "You have IEEE 754 128-bit little endian doubles." >&4 ;;
3746) echo "You have IEEE 754 128-bit big endian doubles." >&4 ;;
3a0bc789
MBT
3757) echo "You have IEEE 754 64-bit mixed endian doubles (32-bit LEs in BE)." >&4 ;;
3768) echo "You have IEEE 754 64-bit mixed endian doubles (32-bit BEs in LE)." >&4 ;;
7253d5da
MBT
3779) echo "You have VAX format F 32-bit PDP-style mixed endian doubles." >&4 ;;
37810) echo "You have VAX format D 64-bit PDP-style mixed endian doubles." >&4 ;;
37911) echo "You have VAX format G 64-bit PDP-style mixed endian doubles." >&4 ;;
48315511
MBT
38012) echo "You have IBM short 32-bit doubles." >&4 ;;
38113) echo "You have IBM long 64-bit doubles." >&4 ;;
38214) echo "You have Cray single 64-bit doubles." >&4 ;;
383*) echo "Cannot figure out your double. You Cyber, or something?" >&4 ;;
63a4f1f4 384esac
3db366a3
MBT
385d_double_style_ieee=$undef
386d_double_style_vax=$undef
387d_double_style_ibm=$undef
388d_double_style_cray=$undef
389case "$doublekind" in
3901|2|3|4|5|6|7|8) d_double_style_ieee=$define ;;
3919|10|11) d_double_style_vax=$define ;;
39212|13) d_double_style_ibm=$define ;;
39314) d_double_style_cray=$define ;;
394esac
395case "$d_double_style_ieee" in
396$define)
397 d_double_has_inf=$define
398 d_double_has_nan=$define
399 d_double_has_negative_zero=$define
400 d_double_has_subnormals=$define
401 ;;
402*)
403 d_double_has_inf=$undef
404 d_double_has_nan=$undef
405 d_double_has_negative_zero=$undef
406 d_double_has_subnormals=$undef
407 ;;
408esac
63a4f1f4
MBT
409$rm_try
410
0065f4af 411: Check print/scan long double stuff
cd276bb8
JH
412echo " "
413
606846d3 414if $test X"$d_longdbl" = X"$define"; then
cd276bb8
JH
415
416echo "Checking how to print long doubles..." >&4
417
418if $test X"$sPRIfldbl" = X -a X"$doublesize" = X"$longdblsize"; then
419 $cat >try.c <<'EOCP'
420#include <sys/types.h>
421#include <stdio.h>
422int main() {
423 double d = 123.456;
424 printf("%.3f\n", d);
425}
426EOCP
427 set try
428 if eval $compile; then
0f00356b 429 yyy=`$run ./try`
cd276bb8
JH
430 case "$yyy" in
431 123.456)
432 sPRIfldbl='"f"'; sPRIgldbl='"g"'; sPRIeldbl='"e"';
0c7f0563 433 sPRIFUldbl='"F"'; sPRIGUldbl='"G"'; sPRIEUldbl='"E"';
cd276bb8
JH
434 echo "We will use %f."
435 ;;
436 esac
437 fi
438fi
439
440if $test X"$sPRIfldbl" = X; then
441 $cat >try.c <<'EOCP'
442#include <sys/types.h>
443#include <stdio.h>
444int main() {
445 long double d = 123.456;
7857a0f2 446 printf("%.3Lf\n", d);
cd276bb8
JH
447}
448EOCP
449 set try
450 if eval $compile; then
0f00356b 451 yyy=`$run ./try`
cd276bb8
JH
452 case "$yyy" in
453 123.456)
7857a0f2 454 sPRIfldbl='"Lf"'; sPRIgldbl='"Lg"'; sPRIeldbl='"Le"';
0c7f0563 455 sPRIFUldbl='"LF"'; sPRIGUldbl='"LG"'; sPRIEUldbl='"LE"';
7857a0f2 456 echo "We will use %Lf."
cd276bb8
JH
457 ;;
458 esac
459 fi
460fi
461
462if $test X"$sPRIfldbl" = X; then
463 $cat >try.c <<'EOCP'
464#include <sys/types.h>
465#include <stdio.h>
466int main() {
467 long double d = 123.456;
7857a0f2 468 printf("%.3llf\n", d);
cd276bb8
JH
469}
470EOCP
471 set try
472 if eval $compile; then
0f00356b 473 yyy=`$run ./try`
cd276bb8
JH
474 case "$yyy" in
475 123.456)
7857a0f2 476 sPRIfldbl='"llf"'; sPRIgldbl='"llg"'; sPRIeldbl='"lle"';
0c7f0563 477 sPRIFUldbl='"llF"'; sPRIGUldbl='"llG"'; sPRIEUldbl='"llE"';
7857a0f2 478 echo "We will use %llf."
cd276bb8
JH
479 ;;
480 esac
481 fi
482fi
483
606846d3 484if $test X"$sPRIfldbl" = X; then
cd276bb8
JH
485 $cat >try.c <<'EOCP'
486#include <sys/types.h>
487#include <stdio.h>
488int main() {
489 long double d = 123.456;
606846d3 490 printf("%.3lf\n", d);
cd276bb8
JH
491}
492EOCP
493 set try
494 if eval $compile; then
0f00356b 495 yyy=`$run ./try`
cd276bb8
JH
496 case "$yyy" in
497 123.456)
606846d3 498 sPRIfldbl='"lf"'; sPRIgldbl='"lg"'; sPRIeldbl='"le"';
0c7f0563 499 sPRIFUldbl='"lF"'; sPRIGUldbl='"lG"'; sPRIEUldbl='"lE"';
606846d3 500 echo "We will use %lf."
cd276bb8
JH
501 ;;
502 esac
503 fi
504fi
505
c84aabe8
JH
506if $test X"$sPRIfldbl" = X; then
507 echo "Cannot figure out how to print long doubles." >&4
6afacc59
JH
508else
509 sSCNfldbl=$sPRIfldbl # expect consistency
c84aabe8
JH
510fi
511
2cb64bf6 512$rm_try
cd276bb8 513
606846d3 514fi # d_longdbl
cd276bb8
JH
515
516case "$sPRIfldbl" in
2cb64bf6
MB
517'') d_PRIfldbl="$undef"; d_PRIgldbl="$undef"; d_PRIeldbl="$undef";
518 d_PRIFUldbl="$undef"; d_PRIGUldbl="$undef"; d_PRIEUldbl="$undef";
6afacc59 519 d_SCNfldbl="$undef";
cd276bb8 520 ;;
2cb64bf6
MB
521*) d_PRIfldbl="$define"; d_PRIgldbl="$define"; d_PRIeldbl="$define";
522 d_PRIFUldbl="$define"; d_PRIGUldbl="$define"; d_PRIEUldbl="$define";
6afacc59 523 d_SCNfldbl="$define";
cd276bb8
JH
524 ;;
525esac
526
63a4f1f4
MBT
527: Before committing on uselongdouble, see whether that looks sane.
528if $test "$uselongdouble" = "$define"; then
529 message=""
530 echo " "
531 echo "Checking if your long double math functions work right..." >&4
532 $cat > try.c <<EOF
533#include <math.h>
534#include <stdio.h>
535int main() {
536 printf("%"$sPRIgldbl"\n", sqrtl(logl(expl(cosl(sinl(0.0L))))+powl(2.0L, 3.0L)));
537}
538EOF
539 case "$osname:$gccversion" in
540 aix:) saveccflags="$ccflags"
541 ccflags="$ccflags -qlongdouble" ;; # to avoid core dump
542 esac
543 set try
544 if eval $compile_ok; then
545 yyy=`$run ./try`
546 fi
547 case "$yyy" in
548 3) echo "Your long double math functions are working correctly." >&4 ;;
549 *) echo "Your long double math functions are broken, not using long doubles." >&4
550 uselongdouble=$undef
551 ;;
552 esac
553 $rm_try
554 case "$osname:$gccversion" in
555 aix:) ccflags="$saveccflags" ;; # restore
556 esac
557fi
558