1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
|
#!./perl -w
BEGIN {
chdir 't' if -d 't';
require './test.pl';
set_up_inc('../lib');
}
use strict;
use Config;
BEGIN {
if ($^O eq 'aix' && $Config{uselongdouble}) {
# FWIW: NaN actually seems to be working decently,
# but Inf is completely broken (e.g. Inf + 0 -> NaN).
skip_all "$^O with long doubles does not have sane inf/nan";
}
unless ($Config{d_double_has_inf} && $Config{d_double_has_nan}) {
skip_all "the doublekind $Config{doublekind} does not have inf/nan";
}
}
my $PInf = "Inf" + 0;
my $NInf = "-Inf" + 0;
my $NaN;
{
local $^W = 0; # warning-ness tested later.
$NaN = "NaN" + 0;
}
my @PInf = ("Inf", "inf", "INF", "+Inf",
"Infinity",
"1.#INF", "1#INF", "1.#INF00");
my @NInf = map { "-$_" } grep { ! /^\+/ } @PInf;
my @NaN = ("NAN", "nan", "qnan", "SNAN", "NanQ", "NANS",
"1.#QNAN", "+1#SNAN", "-1.#NAN", "1#IND", "1.#IND00",
"NAN(123)");
my @printf_fmt = qw(e f g a d u o i b x);
my @packi_fmt = qw(c C s S l L i I n N v V j J w W U);
my @packf_fmt = qw(f d F);
my @packs_fmt = qw(a4 A4 Z5 b20 B20 h10 H10 u);
if ($Config{ivsize} == 8) {
push @packi_fmt, qw(q Q);
}
if ($Config{uselongdouble} && $Config{nvsize} > $Config{doublesize}) {
push @packf_fmt, 'D';
}
# === Inf tests ===
cmp_ok($PInf, '>', 0, "positive infinity");
cmp_ok($NInf, '<', 0, "negative infinity");
cmp_ok($PInf, '>', $NInf, "positive > negative");
cmp_ok($NInf, '==', -$PInf, "negative == -positive");
cmp_ok(-$NInf, '==', $PInf, "--negative == positive");
is($PInf, "Inf", "$PInf value stringifies as Inf");
is($NInf, "-Inf", "$NInf value stringifies as -Inf");
cmp_ok($PInf + 0, '==', $PInf, "+Inf + zero is +Inf");
cmp_ok($NInf + 0, '==', $NInf, "-Inf + zero is -Inf");
cmp_ok($PInf + 1, '==', $PInf, "+Inf + one is +Inf");
cmp_ok($NInf + 1, '==', $NInf, "-Inf + one is -Inf");
cmp_ok($PInf + $PInf, '==', $PInf, "+Inf + Inf is +Inf");
cmp_ok($NInf + $NInf, '==', $NInf, "-Inf - Inf is -Inf");
cmp_ok($PInf * 2, '==', $PInf, "twice Inf is Inf");
cmp_ok($PInf / 2, '==', $PInf, "half of Inf is Inf");
cmp_ok($PInf * $PInf, '==', $PInf, "+Inf * +Inf is +Inf");
cmp_ok($PInf * $NInf, '==', $NInf, "+Inf * -Inf is -Inf");
cmp_ok($NInf * $PInf, '==', $NInf, "-Inf * +Inf is -Inf");
cmp_ok($NInf * $NInf, '==', $PInf, "-Inf * -Inf is +Inf");
is(sprintf("%g", $PInf), "Inf", "$PInf sprintf %g is Inf");
is(sprintf("%a", $PInf), "Inf", "$PInf sprintf %a is Inf");
for my $f (@printf_fmt) {
is(sprintf("%$f", $PInf), "Inf", "$PInf sprintf %$f is Inf");
}
is(sprintf("%+g", $PInf), "+Inf", "$PInf sprintf %+g");
is(sprintf("%+g", $NInf), "-Inf", "$PInf sprintf %+g");
is(sprintf("%4g", $PInf), " Inf", "$PInf sprintf %4g");
is(sprintf("%-4g", $PInf), "Inf ", "$PInf sprintf %-4g");
is(sprintf("%+-5g", $PInf), "+Inf ", "$PInf sprintf %+-5g");
is(sprintf("%-+5g", $PInf), "+Inf ", "$PInf sprintf %-+5g");
is(sprintf("%-+5g", $NInf), "-Inf ", "$NInf sprintf %-+5g");
is(sprintf("%+-5g", $NInf), "-Inf ", "$NInf sprintf %+-5g");
ok(!defined eval { $a = sprintf("%c", $PInf)}, "sprintf %c +Inf undef");
like($@, qr/Cannot printf/, "$PInf sprintf fails");
ok(!defined eval { $a = sprintf("%c", "Inf")},
"stringy sprintf %c +Inf undef");
like($@, qr/Cannot printf/, "stringy $PInf sprintf %c fails");
ok(!defined eval { $a = chr($PInf) }, "chr(+Inf) undef");
like($@, qr/Cannot chr/, "+Inf chr() fails");
ok(!defined eval { $a = chr("Inf") }, "chr(stringy +Inf) undef");
like($@, qr/Cannot chr/, "stringy +Inf chr() fails");
ok(!defined eval { $a = sprintf("%c", $NInf)}, "sprintf %c -Inf undef");
like($@, qr/Cannot printf/, "$NInf sprintf fails");
ok(!defined eval { $a = sprintf("%c", "-Inf")},
"sprintf %c stringy -Inf undef");
like($@, qr/Cannot printf/, "stringy $NInf sprintf %c fails");
ok(!defined eval { $a = chr($NInf) }, "chr(-Inf) undef");
like($@, qr/Cannot chr/, "-Inf chr() fails");
ok(!defined eval { $a = chr("-Inf") }, "chr(stringy -Inf) undef");
like($@, qr/Cannot chr/, "stringy -Inf chr() fails");
for my $f (@packi_fmt) {
undef $a;
ok(!defined eval { $a = pack($f, $PInf) }, "pack $f +Inf undef");
like($@, $f eq 'w' ? qr/Cannot compress Inf/: qr/Cannot pack Inf/,
"+Inf pack $f fails");
undef $a;
ok(!defined eval { $a = pack($f, "Inf") },
"pack $f stringy +Inf undef");
like($@, $f eq 'w' ? qr/Cannot compress Inf/: qr/Cannot pack Inf/,
"stringy +Inf pack $f fails");
undef $a;
ok(!defined eval { $a = pack($f, $NInf) }, "pack $f -Inf undef");
like($@, $f eq 'w' ? qr/Cannot compress -Inf/: qr/Cannot pack -Inf/,
"-Inf pack $f fails");
undef $a;
ok(!defined eval { $a = pack($f, "-Inf") },
"pack $f stringy -Inf undef");
like($@, $f eq 'w' ? qr/Cannot compress -Inf/: qr/Cannot pack -Inf/,
"stringy -Inf pack $f fails");
}
for my $f (@packf_fmt) {
undef $a;
undef $b;
ok(defined eval { $a = pack($f, $PInf) }, "pack $f +Inf defined");
eval { $b = unpack($f, $a) };
cmp_ok($b, '==', $PInf, "pack $f +Inf equals $PInf");
undef $a;
undef $b;
ok(defined eval { $a = pack($f, $NInf) }, "pack $f -Inf defined");
eval { $b = unpack($f, $a) };
cmp_ok($b, '==', $NInf, "pack $f -Inf equals $NInf");
}
for my $f (@packs_fmt) {
undef $a;
ok(defined eval { $a = pack($f, $PInf) }, "pack $f +Inf defined");
is($a, pack($f, "Inf"), "pack $f +Inf same as 'Inf'");
undef $a;
ok(defined eval { $a = pack($f, $NInf) }, "pack $f -Inf defined");
is($a, pack($f, "-Inf"), "pack $f -Inf same as 'Inf'");
}
is eval { unpack "p", pack 'p', $PInf }, "Inf", "pack p +Inf";
is eval { unpack "P3", pack 'P', $PInf }, "Inf", "pack P +Inf";
is eval { unpack "p", pack 'p', $NInf }, "-Inf", "pack p -Inf";
is eval { unpack "P4", pack 'P', $NInf }, "-Inf", "pack P -Inf";
for my $i (@PInf) {
cmp_ok($i + 0 , '==', $PInf, "$i is +Inf");
cmp_ok($i, '>', 0, "$i is positive");
is("@{[$i+0]}", "Inf", "$i value stringifies as Inf");
}
for my $i (@NInf) {
cmp_ok($i + 0, '==', $NInf, "$i is -Inf");
cmp_ok($i, '<', 0, "$i is negative");
is("@{[$i+0]}", "-Inf", "$i value stringifies as -Inf");
}
is($PInf + $PInf, $PInf, "+Inf plus +Inf is +Inf");
is($NInf + $NInf, $NInf, "-Inf plus -Inf is -Inf");
is(1/$PInf, 0, "one per +Inf is zero");
is(1/$NInf, 0, "one per -Inf is zero");
my ($PInfPP, $PInfMM) = ($PInf, $PInf);
my ($NInfPP, $NInfMM) = ($NInf, $NInf);;
$PInfPP++;
$PInfMM--;
$NInfPP++;
$NInfMM--;
is($PInfPP, $PInf, "+Inf++ is +Inf");
is($PInfMM, $PInf, "+Inf-- is +Inf");
is($NInfPP, $NInf, "-Inf++ is -Inf");
is($NInfMM, $NInf, "-Inf-- is -Inf");
ok($PInf, "+Inf is true");
ok($NInf, "-Inf is true");
is(abs($PInf), $PInf, "abs(+Inf) is +Inf");
is(abs($NInf), $PInf, "abs(-Inf) is +Inf");
# One could argue of NaN as the result.
is(int($PInf), $PInf, "int(+Inf) is +Inf");
is(int($NInf), $NInf, "int(-Inf) is -Inf");
is(sqrt($PInf), $PInf, "sqrt(+Inf) is +Inf");
# sqrt $NInf doesn't work because negative is caught
is(exp($PInf), $PInf, "exp(+Inf) is +Inf");
is(exp($NInf), 0, "exp(-Inf) is zero");
SKIP: {
if ($PInf == 0) {
skip "if +Inf == 0 cannot log(+Inf)", 1;
}
is(log($PInf), $PInf, "log(+Inf) is +Inf");
}
# log $NInf doesn't work because negative is caught
is(rand($PInf), $PInf, "rand(+Inf) is +Inf");
is(rand($NInf), $NInf, "rand(-Inf) is -Inf");
# XXX Bit operations?
# +Inf & 1 == +Inf?
# +Inf | 1 == +Inf?
# +Inf ^ 1 == +Inf?
# ~+Inf == 0? or NaN?
# -Inf ... ???
# NaN & 1 == NaN?
# NaN | 1 == NaN?
# NaN ^ 1 == NaN?
# ~NaN == NaN???
# Or just declare insanity and die?
TODO: {
local $::TODO;
my $here = "$^O $Config{osvers}";
$::TODO = "$here: pow (9**9**9) doesn't give Inf"
if $here =~ /^(?:hpux 10|os390)/;
is(9**9**9, $PInf, "9**9**9 is Inf");
}
SKIP: {
my @FInf = qw(Infinite Info Inf123 Infiniti Infinityz);
if ($Config{usequadmath}) {
skip "quadmath strtoflt128() accepts false infinities", scalar @FInf;
}
for my $i (@FInf) {
# Silence "isn't numeric in addition", that's kind of the point.
local $^W = 0;
cmp_ok("$i" + 0, '==', $PInf, "false infinity $i");
}
}
{
# Silence "Non-finite repeat count", that is tested elsewhere.
local $^W = 0;
is("a" x $PInf, "", "x +Inf");
is("a" x $NInf, "", "x -Inf");
}
{
eval 'for my $x (0..$PInf) { last }';
like($@, qr/Range iterator outside integer range/, "0..+Inf fails");
eval 'for my $x ($NInf..0) { last }';
like($@, qr/Range iterator outside integer range/, "-Inf..0 fails");
}
# === NaN ===
cmp_ok($NaN, '!=', $NaN, "NaN is NaN numerically (by not being NaN)");
ok($NaN eq $NaN, "NaN is NaN stringifically");
is("$NaN", "NaN", "$NaN value stringifies as NaN");
{
local $^W = 0; # warning-ness tested later.
is("+NaN" + 0, "NaN", "+NaN is NaN");
is("-NaN" + 0, "NaN", "-NaN is NaN");
}
is($NaN + 0, $NaN, "NaN + zero is NaN");
is($NaN + 1, $NaN, "NaN + one is NaN");
is($NaN * 2, $NaN, "twice NaN is NaN");
is($NaN / 2, $NaN, "half of NaN is NaN");
is($NaN * $NaN, $NaN, "NaN * NaN is NaN");
SKIP: {
if ($NaN == 0) {
skip "NaN looks like zero, avoiding dividing by it", 1;
}
is($NaN / $NaN, $NaN, "NaN / NaN is NaN");
}
for my $f (@printf_fmt) {
is(sprintf("%$f", $NaN), "NaN", "$NaN sprintf %$f is NaN");
}
is(sprintf("%+g", $NaN), "NaN", "$NaN sprintf %+g");
is(sprintf("%4g", $NaN), " NaN", "$NaN sprintf %4g");
is(sprintf("%-4g", $NaN), "NaN ", "$NaN sprintf %-4g");
is(sprintf("%+-5g", $NaN), "NaN ", "$NaN sprintf %+-5g");
is(sprintf("%-+5g", $NaN), "NaN ", "$NaN sprintf %-+5g");
ok(!defined eval { $a = sprintf("%c", $NaN)}, "sprintf %c NaN undef");
like($@, qr/Cannot printf/, "$NaN sprintf fails");
ok(!defined eval { $a = sprintf("%c", "NaN")},
"sprintf %c stringy NaN undef");
like($@, qr/Cannot printf/, "stringy $NaN sprintf %c fails");
ok(!defined eval { $a = chr($NaN) }, "chr NaN undef");
like($@, qr/Cannot chr/, "NaN chr() fails");
ok(!defined eval { $a = chr("NaN") }, "chr stringy NaN undef");
like($@, qr/Cannot chr/, "stringy NaN chr() fails");
for my $f (@packi_fmt) {
ok(!defined eval { $a = pack($f, $NaN) }, "pack $f NaN undef");
like($@, $f eq 'w' ? qr/Cannot compress NaN/: qr/Cannot pack NaN/,
"NaN pack $f fails");
ok(!defined eval { $a = pack($f, "NaN") },
"pack $f stringy NaN undef");
like($@, $f eq 'w' ? qr/Cannot compress NaN/: qr/Cannot pack NaN/,
"stringy NaN pack $f fails");
}
for my $f (@packf_fmt) {
ok(defined eval { $a = pack($f, $NaN) }, "pack $f NaN defined");
eval { $b = unpack($f, $a) };
cmp_ok($b, '!=', $b, "pack $f NaN not-equals $NaN");
}
for my $f (@packs_fmt) {
ok(defined eval { $a = pack($f, $NaN) }, "pack $f NaN defined");
is($a, pack($f, "NaN"), "pack $f NaN same as 'NaN'");
}
is eval { unpack "p", pack 'p', $NaN }, "NaN", "pack p +NaN";
is eval { unpack "P3", pack 'P', $NaN }, "NaN", "pack P +NaN";
for my $i (@NaN) {
cmp_ok($i + 0, '!=', $i + 0, "$i is NaN numerically (by not being NaN)");
is("@{[$i+0]}", "NaN", "$i value stringifies as NaN");
}
ok(!($NaN < 0), "NaN is not lt zero");
ok(!($NaN == 0), "NaN is not == zero");
ok(!($NaN > 0), "NaN is not gt zero");
ok(!($NaN < $NaN), "NaN is not lt NaN");
ok(!($NaN > $NaN), "NaN is not gt NaN");
# is() okay with $NaN because it uses eq.
is($NaN * 0, $NaN, "NaN times zero is NaN");
is($NaN * 2, $NaN, "NaN times two is NaN");
my ($NaNPP, $NaNMM) = ($NaN, $NaN);
$NaNPP++;
$NaNMM--;
is($NaNPP, $NaN, "+NaN++ is NaN");
is($NaNMM, $NaN, "+NaN-- is NaN");
# You might find this surprising (isn't NaN kind of like of undef?)
# but this is how it is.
ok($NaN, "NaN is true");
is(abs($NaN), $NaN, "abs(NaN) is NaN");
is(int($NaN), $NaN, "int(NaN) is NaN");
is(sqrt($NaN), $NaN, "sqrt(NaN) is NaN");
is(exp($NaN), $NaN, "exp(NaN) is NaN");
SKIP: {
if ($NaN == 0) {
skip "if +NaN == 0 cannot log(+NaN)", 1;
}
is(log($NaN), $NaN, "log(NaN) is NaN");
}
is(sin($NaN), $NaN, "sin(NaN) is NaN");
is(rand($NaN), $NaN, "rand(NaN) is NaN");
TODO: {
local $::TODO;
my $here = "$^O $Config{osvers}";
$::TODO = "$here: pow (9**9**9) doesn't give Inf"
if $here =~ /^(?:hpux 10|os390)/;
is(sin(9**9**9), $NaN, "sin(9**9**9) is NaN");
}
SKIP: {
my @FNaN = qw(NaX XNAN Ind Inx);
# Silence "isn't numeric in addition", that's kind of the point.
local $^W = 0;
for my $i (@FNaN) {
cmp_ok("$i" + 0, '==', 0, "false nan $i");
}
}
{
# Silence "Non-finite repeat count", that is tested elsewhere.
local $^W = 0;
is("a" x $NaN, "", "x NaN");
}
# === Tests combining Inf and NaN ===
# is() okay with $NaN because it uses eq.
is($PInf * 0, $NaN, "Inf times zero is NaN");
is($PInf * $NaN, $NaN, "Inf times NaN is NaN");
is($PInf + $NaN, $NaN, "Inf plus NaN is NaN");
is($PInf - $PInf, $NaN, "Inf minus inf is NaN");
is($PInf / $PInf, $NaN, "Inf div inf is NaN");
is($PInf % $PInf, $NaN, "Inf mod inf is NaN");
ok(!($NaN < $PInf), "NaN is not lt +Inf");
ok(!($NaN == $PInf), "NaN is not eq +Inf");
ok(!($NaN > $PInf), "NaN is not gt +Inf");
ok(!($NaN < $NInf), "NaN is not lt -Inf");
ok(!($NaN == $NInf), "NaN is not eq -Inf");
ok(!($NaN > $NInf), "NaN is not gt -Inf");
is(sin($PInf), $NaN, "sin(+Inf) is NaN");
{
eval 'for my $x (0..$NaN) { last }';
like($@, qr/Range iterator outside integer range/, "0..NaN fails");
eval 'for my $x ($NaN..0) { last }';
like($@, qr/Range iterator outside integer range/, "NaN..0 fails");
}
# === Overflows and Underflows ===
# 1e9999 (and 1e-9999) are large (and small) enough for even
# IEEE quadruple precision (magnitude 10**4932, and 10**-4932).
cmp_ok(1e9999, '==', $PInf, "overflow to +Inf (compile time)");
cmp_ok('1e9999', '==', $PInf, "overflow to +Inf (runtime)");
cmp_ok(-1e9999, '==', $NInf, "overflow to -Inf (compile time)");
cmp_ok('-1e9999', '==', $NInf, "overflow to -Inf (runtime)");
cmp_ok(1e-9999, '==', 0, "underflow to 0 (compile time) from pos");
cmp_ok('1e-9999', '==', 0, "underflow to 0 (runtime) from pos");
cmp_ok(-1e-9999, '==', 0, "underflow to 0 (compile time) from neg");
cmp_ok('-1e-9999', '==', 0, "underflow to 0 (runtime) from neg");
# === Warnings triggered when and only when appropriate ===
{
my $w;
local $SIG{__WARN__} = sub { $w = shift };
local $^W = 1;
my $T =
[
[ "inf", 0, $PInf ],
[ "infinity", 0, $PInf ],
[ "infxy", 1, $PInf ],
[ "inf34", 1, $PInf ],
[ "1.#INF", 0, $PInf ],
[ "1.#INFx", 1, $PInf ],
[ "1.#INF00", 0, $PInf ],
[ "1.#INFxy", 1, $PInf ],
[ " inf", 0, $PInf ],
[ "inf ", 0, $PInf ],
[ " inf ", 0, $PInf ],
[ "nan", 0, $NaN ],
[ "nanxy", 1, $NaN ],
[ "nan34", 1, $NaN ],
[ "nanq", 0, $NaN ],
[ "nans", 0, $NaN ],
[ "nanx", 1, $NaN ],
[ "nanqy", 1, $NaN ],
[ "nan(123)", 0, $NaN ],
[ "nan(0x123)", 0, $NaN ],
[ "nan(123xy)", 1, $NaN ],
[ "nan(0x123xy)", 1, $NaN ],
[ "nanq(123)", 0, $NaN ],
[ "nan(123", 1, $NaN ],
[ "nan(", 1, $NaN ],
[ "1.#NANQ", 0, $NaN ],
[ "1.#QNAN", 0, $NaN ],
[ "1.#NANQx", 1, $NaN ],
[ "1.#QNANx", 1, $NaN ],
[ "1.#IND", 0, $NaN ],
[ "1.#IND00", 0, $NaN ],
[ "1.#INDxy", 1, $NaN ],
[ " nan", 0, $NaN ],
[ "nan ", 0, $NaN ],
[ " nan ", 0, $NaN ],
];
for my $t (@$T) {
print "# '$t->[0]' compile time\n";
my $a;
$w = '';
eval '$a = "'.$t->[0].'" + 1';
is("$a", "$t->[2]", "$t->[0] plus one is $t->[2]");
if ($t->[1]) {
like($w, qr/^Argument \Q"$t->[0]"\E isn't numeric/,
"$t->[2] numify warn");
} else {
is($w, "", "no warning expected");
}
print "# '$t->[0]' runtime\n";
my $n = $t->[0];
my $b;
$w = '';
eval '$b = $n + 1';
is("$b", "$t->[2]", "$n plus one is $t->[2]");
if ($t->[1]) {
like($w, qr/^Argument \Q"$n"\E isn't numeric/,
"$n numify warn");
} else {
is($w, "", "no warning expected");
}
}
}
# Size qualifiers shouldn't affect printing Inf/Nan
#
# Prior to the commit which introduced these tests and the fix,
# the code path taken when int-ish formats saw an Inf/Nan was to
# jump to the floating-point handler, but then that would
# warn about (valid) qualifiers.
{
my @w;
local $SIG{__WARN__} = sub { push @w, $_[0] };
for my $format (qw(B b c D d i O o U u X x)) {
# skip unportable: j L q
for my $size (qw(hh h l ll t z)) {
for my $num ($NInf, $PInf, $NaN) {
@w = ();
my $res = eval { sprintf "%${size}${format}", $num; };
my $desc = "sprintf(\"%${size}${format}\", $num)";
if ($format eq 'c') {
like($@, qr/Cannot printf $num with 'c'/, "$desc: like");
}
else {
is($res, $num, "$desc: equality");
}
is (@w, 0, "$desc: warnings")
or do {
diag("got warning: [$_]") for map { chomp; $_} @w;
};
}
}
}
}
done_testing();
|