This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Configure: eliminate some left over debug output
[metaconfig.git] / U / perl / mantbits.U
1 ?RCS: $Id$
2 ?RCS:
3 ?RCS: Copyright (c) 2015 Jarkko Hietaniemi, H.Merijn Brand
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:longdblmantbits doublemantbits nvmantbits: Inlibc cat Compile run \
9         rm_try Setvar echo i_sunmath usequadmath \
10         d_longdbl longdblkind nvsize doublesize longdblsize
11 ?MAKE:  -pick add $@ %<
12 ?S:doublemantbits:
13 ?S:     This symbol, if defined, tells how many mantissa bits
14 ?S:     there are in double precision floating point format.
15 ?S:     Note that this is usually DBL_MANT_DIG minus one, since
16 ?S:     with the standard IEEE 754 formats DBL_MANT_DIG includes
17 ?S:     the implicit bit which doesn't really exist.
18 ?S:.
19 ?S:longdblmantbits:
20 ?S:     This symbol, if defined, tells how many mantissa bits
21 ?S:     there are in long double precision floating point format.
22 ?S:     Note that this can be LDBL_MANT_DIG minus one,
23 ?S:     since LDBL_MANT_DIG can include the IEEE 754 implicit bit.
24 ?S:     The common x86-style 80-bit long double does not have
25 ?S:     an implicit bit.
26 ?S:.
27 ?S:nvmantbits:
28 ?S:     This variable tells how many bits the mantissa of a Perl NV has,
29 ?S:     not including the possible implicit bit.
30 ?S:.
31 ?C:DOUBLEMANTBITS:
32 ?C:     This symbol, if defined, tells how many mantissa bits
33 ?C:     there are in double precision floating point format.
34 ?C:     Note that this is usually DBL_MANT_DIG minus one, since
35 ?C:     with the standard IEEE 754 formats DBL_MANT_DIG includes
36 ?C:     the implicit bit, which doesn't really exist.
37 ?C:.
38 ?C:LONGDBLMANTBITS:
39 ?C:     This symbol, if defined, tells how many mantissa bits
40 ?C:     there are in long double precision floating point format.
41 ?C:     Note that this can be LDBL_MANT_DIG minus one,
42 ?C:     since LDBL_MANT_DIG can include the IEEE 754 implicit bit.
43 ?C:     The common x86-style 80-bit long double does not have
44 ?C:     an implicit bit.
45 ?C:.
46 ?C:NVMANTBITS:
47 ?C:     This symbol, if defined, tells how many mantissa bits
48 ?C:     (not including implicit bit) there are in a Perl NV.
49 ?C:     This depends on which floating point type was chosen.
50 ?C:.
51 ?H:#define DOUBLEMANTBITS  $doublemantbits
52 ?H:#define LONGDBLMANTBITS $longdblmantbits
53 ?H:#define NVMANTBITS      $nvmantbits
54 ?H:.
55 ?F:!try
56 : Check the length of the double mantissa
57 $echo "Checking how many mantissa bits your doubles have..." >&4
58 $cat >try.c <<EOP
59 #$i_sunmath I_SUNMATH
60 #include <float.h>
61 #ifdef I_SUNMATH
62 # include <sunmath.h>
63 #endif
64 #ifdef DBL_MANT_DIG
65 # define BITS (DBL_MANT_DIG - 1) /* the implicit bit does not count */
66 #endif
67 #include <stdio.h>
68 int main(int argc, char *argv[]) {
69 #ifdef BITS
70   printf("%d\n", BITS);
71 #endif
72   return 0;
73 }
74 EOP
75 set try
76 if eval $compile; then
77     doublemantbits=`$run ./try`
78 else
79     doublemantbits="$undef"
80 fi
81 $rm_try
82
83 : Check the length of the longdouble mantissa
84 $echo "Checking how many mantissa bits your long doubles have..." >&4
85 $cat >try.c <<EOP
86 #$i_sunmath I_SUNMATH
87 #include <float.h>
88 #ifdef I_SUNMATH
89 # include <sunmath.h>
90 #endif
91 #$d_longdbl HAS_LONG_DOUBLE
92 #if defined(HAS_LONG_DOUBLE) && defined(LDBL_MANT_DIG)
93 # if ($longdblkind == 3) || ($longdblkind == 4) /* 80-bit extended precision */
94 /* This format has no implicit bit.  Beware, however, that for
95  * this format the bare LDBL_MANT_DIG is misleading for inf/nan:
96  * the top three bits are used for inf (100) / qnan (11x) / snan (101),
97  * and the top bit must have been one since 387, zero is plain invalid.
98  * For normal fp values, the LDBL_MANT_DIG is fine, though. */
99 #  define BITS LDBL_MANT_DIG
100 # elif ($longdblkind == 5 || $longdblkind == 6 || $longdblkind == 7 || $longdblkind == 8) /* double double */
101 /* LDBL_MANT_DIG of 106 (twice 53) would be logical, but for some
102  * reason e.g. Irix thinks 107.  But in any case, we want only
103  * the number of real bits, the implicit bits are of no interest.  */
104 #  define BITS 2 * (DBL_MANT_DIG - 1)
105 # else
106 #  define BITS (LDBL_MANT_DIG - 1) /* the implicit bit does not count */
107 # endif
108 #endif
109 #include <stdio.h>
110 int main(int argc, char *argv[]) {
111 #ifdef BITS
112   printf("%d\n", BITS);
113 #endif
114   return 0;
115 }
116 EOP
117 set try
118 if eval $compile; then
119     longdblmantbits=`$run ./try`
120 else
121     longdblmantbits="$undef"
122 fi
123 $rm_try
124
125 : Check the length of the NV mantissa
126 $echo "Checking how many mantissa bits your NVs have..." >&4
127 if test "X$usequadmath" = "X$define"; then
128   nvmantbits=112 # 128-1-15
129 else
130   if test "X$nvsize" = "X$doublesize"; then
131     nvmantbits="$doublemantbits"
132   else
133      if test "X$nvsize" = "X$longdblsize"; then
134        nvmantbits="$longdblmantbits"
135      else
136        nvmantbits="$undef"
137      fi
138   fi
139 fi
140