Exponentiation with infix operators in (or operating on) the base: Difference between revisions

Content deleted Content added
Thundergnat (talk | contribs)
m →‎{{header|Raku}}: symbolic unary, not infix subtract
Thundergnat (talk | contribs)
m →‎{{header|Raku}}: add explanatory exposition
Line 106: Line 106:


say "\nEasily modified: custom loose infix exponentiation is looser (lower) precedence than unary negation.";
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;</lang>
-> $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}}
{{out}}
<pre>Default precedence: infix exponentiation is tighter (higher) precedence than unary negation.
<pre>Default precedence: infix exponentiation is tighter (higher) precedence than unary negation.
Line 118: Line 121:
x = -5 p = 3 │ -x↑p = 125 │ -(x)↑p = 125 │ (-x)↑p = 125 │ -(x↑p) = 125
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 = 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</pre>
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}}==
=={{header|REXX}}==