Nimber arithmetic: Difference between revisions
m
→{{header|Raku}}: Twiddles; also demo operations on > 64 bit numbers
m (Prolog: call/1 is unnecessary) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: Twiddles; also demo operations on > 64 bit numbers) |
||
Line 710:
{{works with|Rakudo|2020.05}}
{{trans|FreeBasic}}
(or at least, heavily inspired by FreeBasic)
Not limited by integer size. Doesn't rely on twos complement bitwise and.
<lang perl6>sub infix:<⊕> (Int $x, Int $y) { $x +^ $y }
Line 723 ⟶ 725:
(($x +> $h) ⊗ ($y +> $h)) ⊗ (3 +< ($h - 1))
}
# TESTING
my $upto = 26;
Line 730 ⟶ 734:
-> $op, &f {
put " $op
-> $r { put $r.fmt('%2s'), '
put "\n";
}
put "21508 ⊕ 42689 = ", 21508 ⊕ 42689;
put "21508 ⊗ 42689 = ", 21508 ⊗ 42689;
put "2150821508215082150821508 ⊕ 4268942689426894268942689 = ", 2150821508215082150821508 ⊕ 4268942689426894268942689;
put "2150821508215082150821508 ⊗ 4268942689426894268942689 = ", 2150821508215082150821508 ⊗ 4268942689426894268942689;</lang>
{{out}}
<pre> ⊕
───┼────────────────────────────────────────────────────────────────────────────────────────────────────────
0
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
⊗
───┼────────────────────────────────────────────────────────────────────────────────────────────────────────
0
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
21508 ⊕ 42689 = 62149
21508 ⊗ 42689 = 35202
2150821508215082150821508 ⊕ 4268942689426894268942689 = 2722732241575131661744101
2150821508215082150821508 ⊗ 4268942689426894268942689 = 221974472829844568827862736061997038065</pre>
=={{header|Rust}}==
|