Exponentiation with infix operators in (or operating on) the base: Difference between revisions
Exponentiation with infix operators in (or operating on) the base (view source)
Revision as of 14:07, 3 November 2020
, 3 years ago→{{header|Raku}}: add explanatory exposition
Thundergnat (talk | contribs) m (→{{header|Raku}}: symbolic unary, not infix subtract) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: add explanatory exposition) |
||
Line 106:
say "\nEasily modified: custom loose infix exponentiation is looser (lower) precedence than unary negation.";
-> $x, $p { infix-loose-exp($x, $p) } for -5, 2, -5, 3, 5, 2, 5, 3;
say "\nNote that this detects the difference between unary prefix negation and infix subtraction.";
say "-5 - 5 ↑ 3 yields -130 not -1000: ", -5 - 5 ↑ 3;</lang>
{{out}}
<pre>Default precedence: infix exponentiation is tighter (higher) precedence than unary negation.
Line 118 ⟶ 121:
x = -5 p = 3 │ -x↑p = 125 │ -(x)↑p = 125 │ (-x)↑p = 125 │ -(x↑p) = 125
x = 5 p = 2 │ -x↑p = 25 │ -(x)↑p = 25 │ (-x)↑p = 25 │ -(x↑p) = -25
x = 5 p = 3 │ -x↑p = -125 │ -(x)↑p = -125 │ (-x)↑p = -125 │ -(x↑p) = -125
Note that this detects the difference between unary prefix negation and infix subtraction.
-5 - 5 ↑ 3 yields -130 not -1000: -130</pre>
=={{header|REXX}}==
|