-
Notifications
You must be signed in to change notification settings - Fork 135
/
numeric.t
156 lines (139 loc) · 3.71 KB
/
numeric.t
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
use v6;
use Test;
plan 168;
#?DOES 2
sub check($str, $expected_type, $expected_number, $desc?) {
my $result = +$str;
my $description = $desc // $str;
is $result.WHAT.gist, $expected_type.gist, "$description (type)";
is $result, $expected_number, "$description (value)";
}
#?DOES 1
sub f($str) {
my $num = +$str;
#?niecza todo 'Failure'
ok !$num.defined, "+{$str.perl} fails";
}
check '', Int, 0;
check '123', Int, 123;
check ' 123', Int, 123;
check '0000123', Int, 123;
check '1_2_3', Int, 123;
check '+123', Int, 123;
check '-123', Int, -123;
check '3433683820292512484657849089281', Int, 3**64;
f 'a+123';
f '123foo';
f '123+';
f '1__2';
f '123_';
f '123 and stuff';
check '0b111', Int, 7;
check '0b1_1_1', Int, 7;
check '+0b111', Int, 7;
check '-0b111', Int, -7;
# the spec is silent about this one, but rakudo and niecza agree
check '0b_1', Int, 1;
f '0b112';
f '0b';
check '0o77', Int, 63;
check '+0o77', Int, 63;
check '-0o77', Int, -63;
f '0o8';
check '0d123', Int, 123;
check '-0d123', Int, -123;
f '0da';
check '0x123', Int, 291;
check '-0x123', Int, -291;
check '0xa0', Int, 160;
check '-0xA0', Int, -160;
f '0xag';
f '0xaf-';
{
check ':10<42>', Int, 42;
check '-:10<42>', Int, -42;
check '-:1_0<4_2>', Int, -42;
check ':36<aZ>', Int, 395;
check ':2<11>', Int, 3;
#?niecza 6 todo 'Failure'
f ':2<2>';
f ':37<8>';
f ':10<8_>';
f ':10<_8>';
f ':18<>';
f ':10<8';
}
f '123.';
check '123.0', Rat, 123;
check '-123.0', Rat, -123;
check '+123.0', Rat, 123;
check '+1_2_3.0_0', Rat, 123;
check '3/2', Rat, 1.5;
check '+3/2', Rat, 1.5;
check '-3/2', Rat, -1.5;
#?rakudo 5 todo 'Unsure of what val() should accept'
f '-3/-2';
f '3/-2';
f '+3/-2';
f '3.0/2';
f '3/2.0';
{
check '-:10<4_2.3_5>', Rat, -42.35;
check '-:8<4_2.3_5>', Rat, -34.453125;
# from S02-literals/radix.t
f ":2.4<01>";
f ":10<12f>";
f ":1b<10>";
f ":10<>";
f ":_2<01>";
f ":2<_01>";
f ":2<01_>";
f ":_2_<_0_1_>_";
f ":2<1.3>";
f "0b1.1e10";
f ":2<10dlk";
f ":2lks01>";
}
check '123e0', Num, 123;
check '-123e0', Num, -123;
check '+123e0', Num, 123;
check '+123.0e0', Num, 123;
check '+123.0_1e2', Num, 12301;
check '+123.0_1e0_2', Num, 12301;
check '123e-0', Num, 123;
check '-123e+0', Num, -123;
check '123E0', Num, 123;
check '1_2_3E0_0', Num, 123;
check '-123E0', Num, -123;
check '+123E0', Num, 123;
check '123E-0', Num, 123;
check '-123E+0', Num, -123;
check '-123E+0_1', Num, -1230;
check '1230E-1', Num, 123;
check '-12E+1', Num, -120;
f '120e';
f '120e2_';
# TODO: Nums with radix
is +"Inf", 'Inf', 'Inf';
is +"+Inf", 'Inf', '+Inf';
is +"-Inf", '-Inf', '-Inf';
is +"NaN", 'NaN', 'NaN';
{
check '1+2i', Complex, 1+2i;
check '-1-2i', Complex, -1-2i;
check '-1-2\i', Complex, -1-2i;
check '-1.0-2.0\i', Complex, -1-2i;
check '-1.0e0-2.0e0\i', Complex, -1-2i;
check '-1.0e0_0-2.0e0_0\i', Complex, -1-2i;
check '3+Inf\i', Complex, 3+Inf\i;
check 'Inf+2e2i', Complex, Inf+200i;
f '3+3i+4i';
f '3+3+4i';
}
f '3+Infi';
# TODO: Complex with radix
# RT #100778
{
is +Str.new, 0, 'RT #100778'
}
# vim: ft=perl6