File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments