Skip to content

Commit a03e959

Browse files
committed
Test Num.Str roundtrippage is stable
Covers R#1651 rakudo/rakudo#1651
1 parent 9f1fd82 commit a03e959

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

S32-num/stress.t

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use v6;
2+
use Test;
3+
4+
plan 1;
5+
6+
# https://github.com/rakudo/rakudo/issues/1651
7+
subtest 'No drift when roundtripping Num -> Str -> Num -> Str' => {
8+
# In this test, it's fine if the original .Str gives the string that
9+
# doesn't match what the user has entered (since it may be a number that
10+
# doesn't have exact representation in a double). However, .Num.Str
11+
# roundtripping *that* string must produce the first string. i.e. there
12+
# shouldn't be drift after we figure out what the representable number is
13+
14+
my @ranges := (
15+
(^30 .map: { 10**($_*10)}), (^30 .map: {-10**($_*10)}),
16+
(^30 .map: { 10**($_*-10)}), (^30 .map: {-10**($_*-10)}),
17+
3e-324, 3e-320, 3e307
18+
);
19+
20+
plan @ranges * my \iters = 1000;
21+
for @ranges -> \r {
22+
for ^iters {
23+
my \n := r.rand;
24+
my \n1 := n.Str.Num; # get first correct num
25+
my \n2 := n.Str.Num.Str.Num.Str.Num.Str.Num; # second
26+
cmp-ok n1, '===', n2, "{n} roundtrippage is stable";
27+
}
28+
}
29+
}
30+
31+
# vim: ft=perl6

0 commit comments

Comments
 (0)