3 ?RCS: Copyright (c) 1999 Jarkko Hietaniemi
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.
8 ?MAKE:d_PRIfldbl sPRIfldbl d_PRIgldbl d_PRIFUldbl sPRIGUldbl d_PRIEUldbl \
9 sPRIgldbl d_PRIeldbl sPRIeldbl sPRIFUldbl d_PRIGUldbl sPRIEUldbl \
11 sSCNfldbl doublekind: \
12 d_longdbl longdblsize doublesize uselongdouble test echo cat rm_try \
13 Setvar Compile run i_stdlib osname gccversion ccflags
14 ?MAKE: -pick add $@ %<
16 ?S: This variable, if defined, encodes the type of a double:
17 ?S: 1 = IEEE 754 32-bit little endian,
18 ?S: 2 = IEEE 754 32-bit big endian,
19 ?S: 3 = IEEE 754 64-bit little endian,
20 ?S: 4 = IEEE 754 64-bit big endian,
21 ?S: 5 = IEEE 754 128-bit little endian,
22 ?S: 6 = IEEE 754 128-bit big endian,
23 ?S: 7 = IEEE 754 64-bit mixed endian le-be,
24 ?S: 8 = IEEE 754 64-bit mixed endian be-le,
25 ?S: -1 = unknown format.
28 ?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
29 ?S: indicates that stdio has a symbol to print long doubles.
32 ?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
33 ?S: indicates that stdio has a symbol to print long doubles.
36 ?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
37 ?S: indicates that stdio has a symbol to print long doubles.
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: The 'U' in the name is to separate this from d_PRIfldbl so that even
43 ?S: case-blind systems can see the difference.
46 ?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
47 ?S: indicates that stdio has a symbol to print long doubles.
48 ?S: The 'U' in the name is to separate this from d_PRIgldbl so that even
49 ?S: case-blind systems can see the difference.
52 ?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
53 ?S: indicates that stdio has a symbol to print long doubles.
54 ?S: The 'U' in the name is to separate this from d_PRIeldbl so that even
55 ?S: case-blind systems can see the difference.
58 ?S: This variable conditionally defines the PERL_PRIfldbl symbol, which
59 ?S: indicates that stdio has a symbol to scan long doubles.
62 ?S: This variable, if defined, contains the string used by stdio to
63 ?S: format long doubles (format 'f') for output.
66 ?S: This variable, if defined, contains the string used by stdio to
67 ?S: format long doubles (format 'g') for output.
70 ?S: This variable, if defined, contains the string used by stdio to
71 ?S: format long doubles (format 'e') for output.
74 ?S: This variable, if defined, contains the string used by stdio to
75 ?S: format long doubles (format 'F') for output.
76 ?S: The 'U' in the name is to separate this from sPRIfldbl so that even
77 ?S: case-blind systems can see the difference.
80 ?S: This variable, if defined, contains the string used by stdio to
81 ?S: format long doubles (format 'G') for output.
82 ?S: The 'U' in the name is to separate this from sPRIgldbl so that even
83 ?S: case-blind systems can see the difference.
86 ?S: This variable, if defined, contains the string used by stdio to
87 ?S: format long doubles (format 'E') for output.
88 ?S: The 'U' in the name is to separate this from sPRIeldbl so that even
89 ?S: case-blind systems can see the difference.
92 ?S: This variable, if defined, contains the string used by stdio to
93 ?S: format long doubles (format 'f') for input.
96 ?C: This symbol, if defined, contains the string used by stdio to
97 ?C: format long doubles (format 'f') for output.
100 ?C: This symbol, if defined, contains the string used by stdio to
101 ?C: format long doubles (format 'g') for output.
104 ?C: This symbol, if defined, contains the string used by stdio to
105 ?C: format long doubles (format 'e') for output.
108 ?C: This symbol, if defined, contains the string used by stdio to
109 ?C: format long doubles (format 'f') for output.
112 ?C: This symbol, if defined, contains the string used by stdio to
113 ?C: format long doubles (format 'g') for output.
116 ?C: This symbol, if defined, contains the string used by stdio to
117 ?C: format long doubles (format 'e') for output.
120 ?C: This symbol, if defined, contains the string used by stdio to
121 ?C: format long doubles (format 'f') for input.
124 ?C: DOUBLEKIND will be one of
125 ?C: DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN
126 ?C: DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN
127 ?C: DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN
128 ?C: DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN
129 ?C: DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
130 ?C: DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
131 ?C: DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE
132 ?C: DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE
133 ?C: DOUBLE_IS_UNKNOWN_FORMAT
135 ?LINT:known DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN
136 ?LINT:known DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN
137 ?LINT:known DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN
138 ?LINT:known DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN
139 ?LINT:known DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN
140 ?LINT:known DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN
141 ?LINT:known DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE
142 ?LINT:known DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE
143 ?LINT:known DOUBLE_IS_UNKNOWN_FORMAT
144 ?H:#define DOUBLEKIND $doublekind /**/
145 ?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_32_BIT_LITTLE_ENDIAN 1
146 ?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_32_BIT_BIG_ENDIAN 2
147 ?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_64_BIT_LITTLE_ENDIAN 3
148 ?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_64_BIT_BIG_ENDIAN 4
149 ?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_128_BIT_LITTLE_ENDIAN 5
150 ?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_128_BIT_BIG_ENDIAN 6
151 ?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_LE_BE 7
152 ?H:?DOUBLEKIND:#define DOUBLE_IS_IEEE_754_64_BIT_MIXED_ENDIAN_BE_LE 8
153 ?H:?DOUBLEKIND:#define DOUBLE_IS_UNKNOWN_FORMAT -1
154 ?H:#$d_PRIfldbl PERL_PRIfldbl $sPRIfldbl /**/
155 ?H:#$d_PRIgldbl PERL_PRIgldbl $sPRIgldbl /**/
156 ?H:#$d_PRIeldbl PERL_PRIeldbl $sPRIeldbl /**/
157 ?H:#$d_PRIFUldbl PERL_PRIFldbl $sPRIFUldbl /**/
158 ?H:#$d_PRIGUldbl PERL_PRIGldbl $sPRIGUldbl /**/
159 ?H:#$d_PRIEUldbl PERL_PRIEldbl $sPRIEUldbl /**/
160 ?H:#$d_SCNfldbl PERL_SCNfldbl $sSCNfldbl /**/
162 ?T:yyy message saveccflags
165 ?LINT:change uselongdouble
166 : Check what kind of doubles your system has
167 $echo "Checking the kind of doubles you have..." >&4
170 #define DOUBLESIZE $doublesize
175 static const double d = -0.1;
177 unsigned const char* b = (unsigned const char*)(&d);
179 if (b[0] == 0xCD && b[3] == 0xBD) {
180 /* IEEE 754 32-bit little-endian */
184 if (b[0] == 0xBD && b[3] == 0xCD) {
185 /* IEEE 754 32-bit big-endian */
191 if (b[0] == 0x9A && b[7] == 0xBF) {
192 /* IEEE 754 64-bit little-endian */
196 if (b[0] == 0xBF && b[7] == 0x9A) {
197 /* IEEE 754 64-bit big-endian */
201 if (b[0] == 0x99 && b[3] == 0xBF && b[4] == 0x9A && b[7] == 0x99) {
202 /* ARM mixed endian: two little-endian 32-bit floats, in big endian order:
203 * 4 5 6 7 0 1 2 3 (MSB = 7, LSB = 0)
204 * 99 99 b9 bf 9a 99 99 99 */
208 if (b[0] == 0x99 && b[3] == 0x9A && b[4] == 0xBF && b[7] == 0x99) {
209 /* The opposite of case 7, mixed endian: two big-endian 32-bit floats,
210 * in little endian order: 3 2 1 0 7 6 5 4 (MSB = 7, LSB = 0)
211 * 99 99 99 9a bf b9 99 99 */
217 if (b[0] == 0x9A && b[15] == 0xBF) {
218 /* IEEE 754 128-bit little-endian */
222 if (b[0] == 0xBF && b[15] == 0x9A) {
223 /* IEEE 754 128-bit big-endian */
228 /* Then there are old mainframe/miniframe formats like VAX, IBM, and CRAY.
229 * Whether those environments can still build Perl is debatable. */
230 printf("-1\n"); /* unknown */
235 if eval $compile; then
236 doublekind=`$run ./try`
240 case "$doublekind" in
241 1) echo "You have IEEE 754 32-bit little endian doubles." >&4 ;;
242 2) echo "You have IEEE 754 32-bit big endian doubles." >&4 ;;
243 3) echo "You have IEEE 754 64-bit little endian doubles." >&4 ;;
244 4) echo "You have IEEE 754 64-bit big endian doubles." >&4 ;;
245 5) echo "You have IEEE 754 128-bit little endian doubles." >&4 ;;
246 6) echo "You have IEEE 754 128-bit big endian doubles." >&4 ;;
247 7) echo "You have IEEE 754 64-bit mixed endian doubles (32-bit LEs in BE)." >&4 ;;
248 8) echo "You have IEEE 754 64-bit mixed endian doubles (32-bit BEs in LE)." >&4 ;;
249 *) echo "Cannot figure out your double. You VAX, or something?" >&4 ;;
253 : Check print/scan long double stuff
256 if $test X"$d_longdbl" = X"$define"; then
258 echo "Checking how to print long doubles..." >&4
260 if $test X"$sPRIfldbl" = X -a X"$doublesize" = X"$longdblsize"; then
262 #include <sys/types.h>
270 if eval $compile; then
274 sPRIfldbl='"f"'; sPRIgldbl='"g"'; sPRIeldbl='"e"';
275 sPRIFUldbl='"F"'; sPRIGUldbl='"G"'; sPRIEUldbl='"E"';
276 echo "We will use %f."
282 if $test X"$sPRIfldbl" = X; then
284 #include <sys/types.h>
287 long double d = 123.456;
288 printf("%.3Lf\n", d);
292 if eval $compile; then
296 sPRIfldbl='"Lf"'; sPRIgldbl='"Lg"'; sPRIeldbl='"Le"';
297 sPRIFUldbl='"LF"'; sPRIGUldbl='"LG"'; sPRIEUldbl='"LE"';
298 echo "We will use %Lf."
304 if $test X"$sPRIfldbl" = X; then
306 #include <sys/types.h>
309 long double d = 123.456;
310 printf("%.3llf\n", d);
314 if eval $compile; then
318 sPRIfldbl='"llf"'; sPRIgldbl='"llg"'; sPRIeldbl='"lle"';
319 sPRIFUldbl='"llF"'; sPRIGUldbl='"llG"'; sPRIEUldbl='"llE"';
320 echo "We will use %llf."
326 if $test X"$sPRIfldbl" = X; then
328 #include <sys/types.h>
331 long double d = 123.456;
332 printf("%.3lf\n", d);
336 if eval $compile; then
340 sPRIfldbl='"lf"'; sPRIgldbl='"lg"'; sPRIeldbl='"le"';
341 sPRIFUldbl='"lF"'; sPRIGUldbl='"lG"'; sPRIEUldbl='"lE"';
342 echo "We will use %lf."
348 if $test X"$sPRIfldbl" = X; then
349 echo "Cannot figure out how to print long doubles." >&4
351 sSCNfldbl=$sPRIfldbl # expect consistency
359 '') d_PRIfldbl="$undef"; d_PRIgldbl="$undef"; d_PRIeldbl="$undef";
360 d_PRIFUldbl="$undef"; d_PRIGUldbl="$undef"; d_PRIEUldbl="$undef";
363 *) d_PRIfldbl="$define"; d_PRIgldbl="$define"; d_PRIeldbl="$define";
364 d_PRIFUldbl="$define"; d_PRIGUldbl="$define"; d_PRIEUldbl="$define";
365 d_SCNfldbl="$define";
369 : Before committing on uselongdouble, see whether that looks sane.
370 if $test "$uselongdouble" = "$define"; then
373 echo "Checking if your long double math functions work right..." >&4
378 printf("%"$sPRIgldbl"\n", sqrtl(logl(expl(cosl(sinl(0.0L))))+powl(2.0L, 3.0L)));
381 case "$osname:$gccversion" in
382 aix:) saveccflags="$ccflags"
383 ccflags="$ccflags -qlongdouble" ;; # to avoid core dump
386 if eval $compile_ok; then
390 3) echo "Your long double math functions are working correctly." >&4 ;;
391 *) echo "Your long double math functions are broken, not using long doubles." >&4
396 case "$osname:$gccversion" in
397 aix:) ccflags="$saveccflags" ;; # restore