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
1 ?RCS: $Id$
2 ?RCS:
3 ?RCS: Copyright (c) 1999-2016 Jarkko Hietaniemi
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 ?MAKE:d_PRIfldbl sPRIfldbl d_PRIgldbl d_PRIFUldbl sPRIGUldbl d_PRIEUldbl \
9         sPRIgldbl d_PRIeldbl sPRIeldbl sPRIFUldbl d_PRIGUldbl sPRIEUldbl \
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 \
13         sSCNfldbl doublekind: \
14         d_longdbl longdblsize doublesize uselongdouble test echo cat rm_try \
15         Setvar Compile run i_stdlib osname gccversion ccflags
16 ?MAKE:  -pick add $@ %<
17 ?S:doublekind:
18 ?S:     This variable, if defined, encodes the type of a double:
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,
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
30 ?S:     12 = IBM 32bit format
31 ?S:     13 = IBM 64bit format
32 ?S:     14 = Cray 64bit format
33 ?S:     -1 = unknown format.
34 ?S:.
35 ?S:d_PRIfldbl:
36 ?S:     This variable conditionally defines the PERL_PRIfldbl symbol, which
37 ?S:     indicates that stdio has a symbol to print long doubles.
38 ?S:.
39 ?S:d_PRIgldbl:
40 ?S:     This variable conditionally defines the PERL_PRIfldbl symbol, which
41 ?S:     indicates that stdio has a symbol to print long doubles.
42 ?S:.
43 ?S:d_PRIeldbl:
44 ?S:     This variable conditionally defines the PERL_PRIfldbl symbol, which
45 ?S:     indicates that stdio has a symbol to print long doubles.
46 ?S:.
47 ?S:d_PRIFUldbl:
48 ?S:     This variable conditionally defines the PERL_PRIfldbl symbol, which
49 ?S:     indicates that stdio has a symbol to print long doubles.
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.
52 ?S:.
53 ?S:d_PRIGUldbl:
54 ?S:     This variable conditionally defines the PERL_PRIfldbl symbol, which
55 ?S:     indicates that stdio has a symbol to print long doubles.
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.
58 ?S:.
59 ?S:d_PRIEUldbl:
60 ?S:     This variable conditionally defines the PERL_PRIfldbl symbol, which
61 ?S:     indicates that stdio has a symbol to print long doubles.
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.
64 ?S:.
65 ?S:d_SCNfldbl:
66 ?S:     This variable conditionally defines the PERL_PRIfldbl symbol, which
67 ?S:     indicates that stdio has a symbol to scan long doubles.
68 ?S:.
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:.
81 ?S:sPRIFUldbl:
82 ?S:     This variable, if defined, contains the string used by stdio to
83 ?S:     format long doubles (format 'F') for output.
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.
86 ?S:.
87 ?S:sPRIGUldbl:
88 ?S:     This variable, if defined, contains the string used by stdio to
89 ?S:     format long doubles (format 'G') for output.
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.
92 ?S:.
93 ?S:sPRIEUldbl:
94 ?S:     This variable, if defined, contains the string used by stdio to
95 ?S:     format long doubles (format 'E') for output.
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.
98 ?S:.
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:.
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:
108 ?S:     This variable conditionally defines the symbol DOUBLE_HAS_NAN
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:.
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:.
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:.
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
173 ?C:     DOUBLE_IS_VAX_F_FLOAT
174 ?C:     DOUBLE_IS_VAX_D_FLOAT
175 ?C:     DOUBLE_IS_VAX_G_FLOAT
176 ?C:     DOUBLE_IS_IBM_SINGLE_32_BIT
177 ?C:     DOUBLE_IS_IBM_DOUBLE_64_BIT
178 ?C:     DOUBLE_IS_CRAY_SINGLE_64_BIT
179 ?C:     DOUBLE_IS_UNKNOWN_FORMAT
180 ?C:.
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:.
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
221 ?LINT:known DOUBLE_IS_VAX_F_FLOAT
222 ?LINT:known DOUBLE_IS_VAX_D_FLOAT
223 ?LINT:known DOUBLE_IS_VAX_G_FLOAT
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
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
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
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
243 ?H:?DOUBLEKIND:#define DOUBLE_IS_UNKNOWN_FORMAT         -1
244 ?H:#$d_PRIfldbl PERL_PRIfldbl   $sPRIfldbl      /**/
245 ?H:#$d_PRIgldbl PERL_PRIgldbl   $sPRIgldbl      /**/
246 ?H:#$d_PRIeldbl PERL_PRIeldbl   $sPRIeldbl      /**/
247 ?H:#$d_PRIFUldbl PERL_PRIFldbl  $sPRIFUldbl     /**/
248 ?H:#$d_PRIGUldbl PERL_PRIGldbl  $sPRIGUldbl     /**/
249 ?H:#$d_PRIEUldbl PERL_PRIEldbl  $sPRIEUldbl     /**/
250 ?H:#$d_SCNfldbl PERL_SCNfldbl   $sSCNfldbl      /**/
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
259 ?H:.
260 ?T:yyy message saveccflags
261 ?F:!try
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>
273 static const double d = -0.1;
274 int 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   }
287   if (b[0] == 0xCC && b[3] == 0xCC) {
288     /* VAX format F, 32-bit PDP-style mixed endian. */
289     printf("9\n");
290     exit(0);
291   }
292   if (b[0] == 0xC0 && b[3] == 0x9A) {
293     /* IBM single 32-bit */
294     printf("12\n");
295     exit(0);
296   }
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   }
323   if (b[0] == 0xCC && b[7] == 0xCC) {
324    /* VAX format D, 64-bit PDP-style mixed endian. */
325     printf("10\n");
326     exit(0);
327   }
328   if (b[0] == 0xD9 && b[7] == 0x99) {
329    /* VAX format G, 64-bit PDP-style mixed endian. */
330     printf("11\n");
331     exit(0);
332   }
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   }
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
356   /* Then there are old mainframe/miniframe formats like IBM and CRAY.
357    * Whether those environments can still build Perl is debatable. */
358   printf("-1\n"); /* unknown */
359   exit(0);
360 }
361 EOP
362 set try
363 if eval $compile; then
364     doublekind=`$run ./try`
365 else
366     doublekind=-1
367 fi
368 case "$doublekind" in
369 1) echo "You have IEEE 754 32-bit little endian doubles." >&4 ;;
370 2) echo "You have IEEE 754 32-bit big endian doubles." >&4 ;;
371 3) echo "You have IEEE 754 64-bit little endian doubles." >&4 ;;
372 4) echo "You have IEEE 754 64-bit big endian doubles." >&4 ;;
373 5) echo "You have IEEE 754 128-bit little endian doubles." >&4 ;;
374 6) echo "You have IEEE 754 128-bit big endian doubles." >&4 ;;
375 7) echo "You have IEEE 754 64-bit mixed endian doubles (32-bit LEs in BE)." >&4 ;;
376 8) echo "You have IEEE 754 64-bit mixed endian doubles (32-bit BEs in LE)." >&4 ;;
377 9) echo "You have VAX format F 32-bit PDP-style mixed endian doubles." >&4 ;;
378 10) echo "You have VAX format D 64-bit PDP-style mixed endian doubles." >&4 ;;
379 11) echo "You have VAX format G 64-bit PDP-style mixed endian doubles." >&4 ;;
380 12) echo "You have IBM short 32-bit doubles." >&4 ;;
381 13) echo "You have IBM long 64-bit doubles." >&4 ;;
382 14) echo "You have Cray single 64-bit doubles." >&4 ;;
383 *) echo "Cannot figure out your double.  You Cyber, or something?" >&4 ;;
384 esac
385 d_double_style_ieee=$undef
386 d_double_style_vax=$undef
387 d_double_style_ibm=$undef
388 d_double_style_cray=$undef
389 case "$doublekind" in
390 1|2|3|4|5|6|7|8) d_double_style_ieee=$define ;;
391 9|10|11) d_double_style_vax=$define ;;
392 12|13) d_double_style_ibm=$define ;;
393 14) d_double_style_cray=$define ;;
394 esac
395 case "$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     ;;
408 esac
409 $rm_try
410
411 : Check print/scan long double stuff
412 echo " "
413
414 if $test X"$d_longdbl" = X"$define"; then
415
416 echo "Checking how to print long doubles..." >&4
417
418 if $test X"$sPRIfldbl" = X -a X"$doublesize" = X"$longdblsize"; then
419         $cat >try.c <<'EOCP'
420 #include <sys/types.h>
421 #include <stdio.h>
422 int main() {
423   double d = 123.456;
424   printf("%.3f\n", d);
425 }
426 EOCP
427         set try
428         if eval $compile; then
429                 yyy=`$run ./try`
430                 case "$yyy" in
431                 123.456)
432                         sPRIfldbl='"f"'; sPRIgldbl='"g"'; sPRIeldbl='"e"';
433                         sPRIFUldbl='"F"'; sPRIGUldbl='"G"'; sPRIEUldbl='"E"';
434                         echo "We will use %f."
435                         ;;
436                 esac
437         fi
438 fi
439
440 if $test X"$sPRIfldbl" = X; then
441         $cat >try.c <<'EOCP'
442 #include <sys/types.h>
443 #include <stdio.h>
444 int main() {
445   long double d = 123.456;
446   printf("%.3Lf\n", d);
447 }
448 EOCP
449         set try
450         if eval $compile; then
451                 yyy=`$run ./try`
452                 case "$yyy" in
453                 123.456)
454                         sPRIfldbl='"Lf"'; sPRIgldbl='"Lg"'; sPRIeldbl='"Le"';
455                         sPRIFUldbl='"LF"'; sPRIGUldbl='"LG"'; sPRIEUldbl='"LE"';
456                         echo "We will use %Lf."
457                         ;;
458                 esac
459         fi
460 fi
461
462 if $test X"$sPRIfldbl" = X; then
463         $cat >try.c <<'EOCP'
464 #include <sys/types.h>
465 #include <stdio.h>
466 int main() {
467   long double d = 123.456;
468   printf("%.3llf\n", d);
469 }
470 EOCP
471         set try
472         if eval $compile; then
473                 yyy=`$run ./try`
474                 case "$yyy" in
475                 123.456)
476                         sPRIfldbl='"llf"'; sPRIgldbl='"llg"'; sPRIeldbl='"lle"';
477                         sPRIFUldbl='"llF"'; sPRIGUldbl='"llG"'; sPRIEUldbl='"llE"';
478                         echo "We will use %llf."
479                         ;;
480                 esac
481         fi
482 fi
483
484 if $test X"$sPRIfldbl" = X; then
485         $cat >try.c <<'EOCP'
486 #include <sys/types.h>
487 #include <stdio.h>
488 int main() {
489   long double d = 123.456;
490   printf("%.3lf\n", d);
491 }
492 EOCP
493         set try
494         if eval $compile; then
495                 yyy=`$run ./try`
496                 case "$yyy" in
497                 123.456)
498                         sPRIfldbl='"lf"'; sPRIgldbl='"lg"'; sPRIeldbl='"le"';
499                         sPRIFUldbl='"lF"'; sPRIGUldbl='"lG"'; sPRIEUldbl='"lE"';
500                         echo "We will use %lf."
501                         ;;
502                 esac
503         fi
504 fi
505
506 if $test X"$sPRIfldbl" = X; then
507         echo "Cannot figure out how to print long doubles." >&4
508 else
509         sSCNfldbl=$sPRIfldbl    # expect consistency
510 fi
511
512 $rm_try
513
514 fi # d_longdbl
515
516 case "$sPRIfldbl" in
517 '')     d_PRIfldbl="$undef"; d_PRIgldbl="$undef"; d_PRIeldbl="$undef";
518         d_PRIFUldbl="$undef"; d_PRIGUldbl="$undef"; d_PRIEUldbl="$undef";
519         d_SCNfldbl="$undef";
520         ;;
521 *)      d_PRIfldbl="$define"; d_PRIgldbl="$define"; d_PRIeldbl="$define";
522         d_PRIFUldbl="$define"; d_PRIGUldbl="$define"; d_PRIEUldbl="$define";
523         d_SCNfldbl="$define";
524         ;;
525 esac
526
527 : Before committing on uselongdouble, see whether that looks sane.
528 if $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>
535 int main() {
536   printf("%"$sPRIgldbl"\n", sqrtl(logl(expl(cosl(sinl(0.0L))))+powl(2.0L, 3.0L)));
537 }
538 EOF
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
557 fi
558