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 19:04, 4 March 2024
, 2 months ago→{{header|langur}}
Langurmonkey (talk | contribs) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 320:
{{out}}
<pre>Same as FreeBASIC entry.</pre>
=={{header|EasyLang}}==
<syntaxhighlight>
for x in [ -5 5 ]
for p in [ 2 3 ]
print x & "^" & p & " = " & pow x p
.
.
</syntaxhighlight>
=={{header|F_Sharp|F#}}==
Line 471 ⟶ 480:
{{out}}
<pre>[-25, -25, 25, -25]
[-125, -125, -125, -125]
</pre>
Line 979 ⟶ 982:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
Wren uses the pow() method for exponentiation of numbers and, whilst it supports operator overloading, there is no way of adding a suitable infix operator to the existing Num class or inheriting from that class.
However, what we can do is to wrap Num objects in a new Num2 class and then add exponentiation and unary minus operators to that.
Ideally what we'd like to do is to use a new operator such as '**' for exponentiation (because '^' is the bitwise exclusive or operator) but we can only overload existing operators with their existing precedence and so, for the purposes of this task, '^' is the only realistic choice.
<syntaxhighlight lang="
class Num2 {
|