Tropical algebra overloading: Difference between revisions

Content added Content deleted
m (→‎{{header|Raku}}: reduce noise)
m (→‎{{header|Raku}}: test relative precedence of ↑ and ⊕)
Line 607: Line 607:
sub infix:<⊗> (Real $a, Real $b) is equiv(&[×]) { $a + $b }
sub infix:<⊗> (Real $a, Real $b) is equiv(&[×]) { $a + $b }
sub infix:<↑> (Real $a, Int $b) is equiv(&[**]) { [⊗] $a xx $b }
sub infix:<↑> (Real $a, Int $b) is equiv(&[**]) { [⊗] $a xx $b }

use Test;
use Test;

is-deeply( 2 ⊗ -2, 0, '2 ⊗ -2 == 0' );
is-deeply( 2 ⊗ -2, 0, '2 ⊗ -2 == 0' );
is-deeply( -0.001 ⊕ -Inf, -0.001, '-0.001 ⊕ -Inf == -0.001' );
is-deeply( -0.001 ⊕ -Inf, -0.001, '-0.001 ⊕ -Inf == -0.001' );
Line 616: Line 616:
is-deeply( -0.5 ⊗ 0, -0.5, '-0.5 ⊗ 0 == -0.5' );
is-deeply( -0.5 ⊗ 0, -0.5, '-0.5 ⊗ 0 == -0.5' );
is-deeply( 5 ↑ 7, 35, '5 ↑ 7 == 35' );
is-deeply( 5 ↑ 7, 35, '5 ↑ 7 == 35' );
is-deeply( 5 ⊗ (8 ⊕ 7), 5 ⊗ 8 ⊕ 5 ⊗ 7, '5 ⊗ (8 ⊕ 7) == 5 ⊗ 8 ⊕ 5 ⊗ 7');</lang>
is-deeply( 5 ⊗ (8 ⊕ 7), 5 ⊗ 8 ⊕ 5 ⊗ 7, '5 ⊗ (8 ⊕ 7) == 5 ⊗ 8 ⊕ 5 ⊗ 7');
is-deeply( 5 ↑ 7 ⊕ 6 ↑ 6, 36, '5 ↑ 7 ⊕ 6 ↑ 6 == 36');</lang>
{{out}}
{{out}}
<pre>ok 1 - 2 ⊗ -2 == 0
<pre>ok 1 - 2 ⊗ -2 == 0
Line 624: Line 625:
ok 5 - -0.5 ⊗ 0 == -0.5
ok 5 - -0.5 ⊗ 0 == -0.5
ok 6 - 5 ↑ 7 == 35
ok 6 - 5 ↑ 7 == 35
ok 7 - 5 ⊗ (8 ⊕ 7) == 5 ⊗ 8 ⊕ 5 ⊗ 7</pre>
ok 7 - 5 ⊗ (8 ⊕ 7) == 5 ⊗ 8 ⊕ 5 ⊗ 7
ok 8 - 5 ↑ 7 ⊕ 6 ↑ 6 == 36</pre>


=={{header|REXX}}==
=={{header|REXX}}==