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

m
m (→‎{{header|Wren}}: Minor tidy)
Line 979:
=={{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.
 
Also inheriting from the Num class is not recommended and will probably be banned altogether from the next version.
 
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="ecmascriptwren">import "./fmt" for Fmt
 
class Num2 {
9,477

edits