15 # Test hexfloat literals.
41 is(0x0.100p0, 0.0625);
45 is(0x1.11p0, 1.06640625);
46 is(0x1.111p0, 1.066650390625);
70 is(0x12p23, 0x12 << 23);
73 is(0x1p-2, 1 / (1 << 2));
74 is(0x1p-3, 1 / (1 << 3));
75 is(0x3p-4, 3 / (1 << 4));
76 is(0x3p-5, 3 / (1 << 5));
77 is(0x12p-23, 0x12 / (1 << 23));
92 # Hexdigits (lowercase).
99 is(0xab.cdp+0, 171.80078125);
101 # Uppercase hexdigits and exponent prefix.
105 is(0xAB.CDP+0, 171.80078125);
108 is(0xa_b.c_dp+1_2, 703696);
110 # Note that the hexfloat representation is not unique since the
111 # exponent can be shifted, and the hexdigits with it: this is no
112 # different from 3e4 cf 30e3 cf 30000. The shifting of the hexdigits
113 # makes it look stranger, though: 0xap1 == 0x5p2.
115 # [perl #127183], try some non-canonical forms.
117 skip("nv_preserves_uv_bits is $Config{nv_preserves_uv_bits} not 53", 3)
118 unless ($Config{nv_preserves_uv_bits} == 53);
119 is(0x0.b17217f7d1cf78p0, 0x1.62e42fefa39efp-1);
120 is(0x0.58b90bfbe8e7bcp1, 0x1.62e42fefa39efp-1);
121 is(0x0.2c5c85fdf473dep2, 0x1.62e42fefa39efp-1);
124 # Needs to use within() instead of is() because of long doubles.
125 within(0x1.99999999999ap-4, 0.1, 1e-9);
126 within(0x3.333333333333p-5, 0.1, 1e-9);
127 within(0xc.cccccccccccdp-7, 0.1, 1e-9);
131 local $SIG{__WARN__} = sub { $warn = shift };
139 { # Test certain things that are not hexfloats and should stay that way.
141 like(get_warn(), qr/Missing operator before p3/);
144 like(get_warn(), qr/Missing operator before p3/);
151 eval '$a = eval "0x.3"';
155 eval '$a = eval "0xc.3"';
159 eval '$a = eval "0x.p3"';
166 if ($Config{nv_preserves_uv_bits} == 53) {
169 eval '0x1_0000_0000_0000_0p0';
170 is(get_warn(), undef);
172 eval '0x2_0000_0000_0000_0p0';
173 like(get_warn(), qr/^Hexadecimal float: mantissa overflow/);
175 eval '0x1.0000_0000_0000_0p0';
176 is(get_warn(), undef);
178 eval '0x2.0000_0000_0000_0p0';
179 like(get_warn(), qr/^Hexadecimal float: mantissa overflow/);
182 is(get_warn(), undef);
185 like(get_warn(), qr/^Hexadecimal float: exponent underflow/);
187 eval '0x1.fffffffffffffp+1023';
188 is(get_warn(), undef);
190 eval '0x1.fffffffffffffp+1024';
191 like(get_warn(), qr/^Hexadecimal float: exponent overflow/);
194 eval '$a = 0x111.0000000000000p+0'; # 12 zeros.
195 like(get_warn(), qr/^Hexadecimal float: mantissa overflow/);
198 # The 13 zeros would be enough to push the hi-order digits
202 eval '$a = 0x111.0000000000000p+0'; # 13 zeros.
203 like(get_warn(), qr/^Hexadecimal float: mantissa overflow/);
207 eval '$a = 0x111.00000000000000p+0'; # 14 zeros.
208 like(get_warn(), qr/^Hexadecimal float: mantissa overflow/);
212 eval '$a = 0xfffffffffffffp0'; # 52 bits.
213 is(get_warn(), undef);
214 is($a, 4.5035996273705e+15);
217 eval '$a = 0xfffffffffffff.8p0'; # 53 bits.
218 is(get_warn(), undef);
219 is($a, 4.5035996273705e+15);
222 eval '$a = 0xfffffffffffff.cp0'; # 54 bits.
223 like(get_warn(), qr/^Hexadecimal float: mantissa overflow/);
224 is($a, 4.5035996273705e+15);
227 eval '$a = 0xf.ffffffffffffp0'; # 52 bits.
228 is(get_warn(), undef);
232 eval '$a = 0xf.ffffffffffff8p0'; # 53 bits.
233 is(get_warn(), undef);
237 eval '$a = 0xf.ffffffffffffcp0'; # 54 bits.
238 like(get_warn(), qr/^Hexadecimal float: mantissa overflow/);
241 print "# skipping warning tests\n";
242 skip "nv_preserves_uv_bits is $Config{nv_preserves_uv_bits} not 53", 26;
246 # [perl #128919] limited exponent range in hex fp literal with long double
248 skip("non-80-bit-long-double", 4)
249 unless ($Config{uselongdouble} &&
250 ($Config{nvsize} == 16 || $Config{nvsize} == 12) &&
251 ($Config{long_double_style_ieee_extended}));
252 is(0x1p-1074, 4.94065645841246544e-324);
253 is(0x1p-1075, 2.47032822920623272e-324, '[perl #128919]');
254 is(0x1p-1076, 1.23516411460311636e-324);
255 is(0x1p-16445, 3.6451995318824746e-4951);
258 # [perl #131894] parsing long binaryish floating point literals used to
259 # perform illegal bit shifts
261 skip("non-64-bit NVs", 1)
262 unless $Config{nvsize} == 8 && $Config{d_double_style_ieee};
263 is sprintf("%a", eval("0x030000000000000.1p0")), "0x1.8p+53";
264 is sprintf("%a", eval("01400000000000000000.1p0")), "0x1.8p+54";
265 is sprintf("%a", eval("0b110000000000000000000000000000000000000000000000000000000.1p0")), "0x1.8p+56";
268 # the implementation also allow for octal and binary fp
282 # sprintf %a/%A testing is done in sprintf2.t,
283 # trickier than necessary because of long doubles,
284 # and because looseness of the spec.