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 09:46, 4 November 2020
, 3 years agojulia example
Thundergnat (talk | contribs) (→{{header|Raku}}: DRY, pass operations as strings which requires EVAL and precludes sigiless variables) |
(julia example) |
||
Line 84:
5 3 -x**p -125 -(x)**p -125 (-x)**p -125 -(x**p) -125
</pre>
=={{header|Julia}}==
In Julia, the ^ symbol is the power infix operator. The ^ operator has a higher precedence than the - operator,
so -5^2 is -25 and (-5)^2 is 25.
<lang julia>
for x in [-5, 5], p in [2, 3]
println("x is", lpad(x, 3), ", p is $p, -x^p is", lpad(-x^p, 4), ", -(x)^p is",
lpad(-(x)^p, 5), ", (-x)^p is", lpad((-x)^p, 5), ", -(x^p) is", lpad(-(x^p), 5))
end
</lang>{{out}}
<pre>
x is -5, p is 2, -x^p is -25, -(x)^p is -25, (-x)^p is 25, -(x^p) is -25
x is -5, p is 3, -x^p is 125, -(x)^p is 125, (-x)^p is 125, -(x^p) is 125
x is 5, p is 2, -x^p is -25, -(x)^p is -25, (-x)^p is 25, -(x^p) is -25
x is 5, p is 3, -x^p is-125, -(x)^p is -125, (-x)^p is -125, -(x^p) is -125
</pre>
=={{header|Raku}}==
|