Exponentiation order: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
No edit summary
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(8 intermediate revisions by 5 users not shown)
Line 108:
(5**3)**2: +15625
5**(3**2): +1953125
</pre>
 
=={{header|ALGOL-M}}==
The eponentiation operator ** in ALGOL-M works only on integer operands.
<syntaxhighlight lang = "ALGOL">
begin
 
write("5**3**2 = ", 5**3**2);
write("(5**3)**2 = ", (5**3)**2);
write("5**(3**2) = ", 5**(3**2));
 
end
</syntaxhighlight>
{{out}}
The third expression results in a value that exceeds the maximum integer value of 16383. Sadly, ALGOL-M emits no warning or error message when this occurs but simply gives the wrong answer.
<pre>
5**3**2 = 15625
(5**3)**2 = 15625
5**(3**2) = -12955
</pre>
 
Line 521 ⟶ 540:
<pre>(5 ^ 3) ^ 2 = 15625
5 ^ (3 ^ 2) = 1953125</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
print "(5 ^ 3) ^ 2 = " & pow (pow 5 3) 2
print "5 ^ (3 ^ 2) = " & pow 5 pow 3 2
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 879 ⟶ 904:
5 3 2 ^ ^ 1953125.0
5 3 ^ 2 ^ 15625.0
</pre>
 
=={{header|MiniScript}}==
REPL output.
{{out}}
<pre>
]5^3^2
15625
](5^3)^2
15625
]5^(3^2)
1953125
</pre>
 
Line 1,198 ⟶ 1,235:
(5^3)^2 =>15625
5^(3^2) =>1953125
</pre>
 
=={{header|RPL}}==
When using reverse Polish notation, there is no parenthesis: the user must decide the exponentiation order.
When using algebraic notation:
'5^3^2' →NUM
'(5^3)^2' →NUM
'5^(3^2)' →NUM
{{out}}
<pre>
3: 15625
2: 15625
1: 1953125
</pre>
 
Line 1,224 ⟶ 1,274:
(5**3)**2 = 15625
5**(3**2) = 1953125
</pre>
 
=={{header|S-BASIC}}==
The exponentiation operator ^ works on both integer and real operands. Numeric constants in expressions are taken to be of type real, which is useful here, because the third result exceeds S-BASIC's manximum integer value of 32767.
<syntaxhighlight lang = "BASIC">
print "5^3^2 : "; 5 ^ 3 ^ 2
print "(5^3)^2 : "; (5 ^ 3) ^ 2
print "5^(3^2) : "; 5 ^ (3 ^ 2)
 
end
</syntaxhighlight>
{{out}}
<pre>
5^3^2 : 15625
(5^3)^2 : 15625
5^(3^2) : 1.95312E+6
</pre>
 
Line 1,419 ⟶ 1,485:
{{libheader|Wren-fmt}}
Wren doesn't have an exponentiation operator as such but the Num class has a ''pow'' method which does the same thing.
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var ops = [ "5**3**2", "(5**3)**2", "5**(3**2)" ]
var results = [ 5.pow(3).pow(2), (5.pow(3)).pow(2), 5.pow(3.pow(2)) ]
for (i in 0...ops.count) {
SystemFmt.print("%(Fmt.s($-99s -> $d", ops[i])), -> %(results[i])")
}</syntaxhighlight>
 
9,479

edits