Exponentiation order: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Nim}}: fix markup)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(18 intermediate revisions by 13 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 182 ⟶ 201:
 
=={{header|BASIC}}==
==={{header|Sinclair ZX81Applesoft BASIC}}===
<syntaxhighlight lang="basicgwbasic">10?"5^3^2 PRINT = "5** ^ 3** ^ 2 CHR$ (13)"(5^3)^2 = ";(5** ^ 3**) ^ 2 CHR$ (13)"5^(3^2) = "5 ^ (3 ^ 2);</syntaxhighlight>
20 PRINT "(5**3)**2 = ";(5**3)**2
30 PRINT "5**(3**2) = ";5**(3**2)</syntaxhighlight>
{{out}}
<pre>5**^3**^2 = 15625
(5**^3)**^2 = 15625
5**^(3**^2) = 1953125.01</pre>
==={{header|BASIC256}}===
{{works with|QBasic}}
{{works with|FreeBASIC}}
{{works with|True BASIC}}
{{works with|Run BASIC}}
<syntaxhighlight lang="freebasic">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) = 1953125</pre>
 
==={{header|BBC BASIC}}===
Line 195 ⟶ 225:
PRINT "(5^3)^2 = "; (5^3)^2
PRINT "5^(3^2) = "; 5^(3^2)</syntaxhighlight>
{{out}}
<pre>5^3^2 = 15625
(5^3)^2 = 15625
5^(3^2) = 1953125</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">10 print "5^3^2 = "5^3^2
20 print "(5^3)^2 = "(5^3)^2
30 print "5^(3^2) = "5^(3^2)</syntaxhighlight>
{{out}}
<pre>5^3^2 = 15625
(5^3)^2 = 15625
5^(3^2) = 1953125</pre>
 
==={{header|GW-BASIC}}===
{{works with|Applesoft BASIC}}
{{works with|Chipmunk Basic}}
{{works with|MSX_BASIC}}
{{works with|PC-BASIC|any}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">10 PRINT "5^3^2 =" 5^3^2
20 PRINT "(5^3)^2 =" (5^3)^2
30 PRINT "5^(3^2) =" 5^(3^2)</syntaxhighlight>
{{out}}
<pre>5^3^2 = 15625
Line 209 ⟶ 263:
5^(3^2) = 1953125</pre>
 
==={{header|MSX Basic}}===
<syntaxhighlight lang="qbasic">10 PRINT "5^3^2 =" 5^3^2
20 PRINT "(5^3)^2 =" (5^3)^2
30 PRINT "5^(3^2) =" 5^(3^2)</syntaxhighlight>
{{out}}
<pre>5^3^2 = 15625
(5^3)^2 = 15625
5^(3^2) = 1953125</pre>
 
==={{header|PureBasic}}===
In the PureBasic it is impossible to show the result of: 5^3^2
<syntaxhighlight lang="vb">OpenConsole()
PrintN("(5^3)^2 = " + Str(Pow(Pow(5, 3), 2)))
PrintN("5^(3^2) = " + Str(Pow(5, (Pow(3, 2)))))
CloseConsole()</syntaxhighlight>
{{out}}
<pre>(5^3)^2 = 15625
5^(3^2) = 1953125</pre>
 
==={{header|QBasic}}===
Line 221 ⟶ 293:
PRINT "5^(3^2) ="; 5^(3^2)
END</syntaxhighlight>
{{out}}
<pre>5^3^2 = 15625
(5^3)^2 = 15625
5^(3^2) = 1953125</pre>
 
==={{header|BASIC256}}===
{{works with|QBasic}}
{{works with|FreeBASIC}}
{{works with|True BASIC}}
{{works with|Run BASIC}}
<syntaxhighlight lang="freebasic">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
Line 263 ⟶ 321:
PRINT "5^(3^2) ="; 5^(3^2)
END</syntaxhighlight>
{{out}}
<pre>5^3^2 = 15625
(5^3)^2 = 15625
5^(3^2) = 1953125</pre>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "Exponentiation order"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
PRINT "5^3^2 ="; 5**3**2
PRINT "(5^3)^2 ="; (5**3)**2
PRINT "5^(3^2) ="; 5**(3**2)
END FUNCTION
END PROGRAM</syntaxhighlight>
{{out}}
<pre>5^3^2 = 15625
Line 282 ⟶ 358:
5^(3^2) = 1953125</pre>
 
==={{header|Sinclair ZX81 BASIC}}===
<syntaxhighlight lang="basic">10 PRINT "5**3**2 = ";5**3**2
20 PRINT "(5**3)**2 = ";(5**3)**2
30 PRINT "5**(3**2) = ";5**(3**2)</syntaxhighlight>
{{out}}
<pre>5**3**2 = 15625
(5**3)**2 = 15625
5**(3**2) = 1953125</pre>
 
=={{header|Bracmat}}==
Line 422 ⟶ 506:
5 ^^ (3 ^^ 2) = 1953125
[5, 3, 2].reduce!pow = 15625</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|Math,SysUtils,StdCtrls}}
Delphi doesn't have exponentiation but it does have the "Power" function in the math library
 
<syntaxhighlight lang="Delphi">
procedure ExponentDemo(Memo: TMemo);
begin
Memo.Lines.Add('5^3^2 = '+FloatToStrF(Power(5,Power(3,2)),ffNumber,18,0));
Memo.Lines.Add('(5^3)^2 = '+FloatToStrF(Power(Power(5,3),2),ffNumber,18,0));
Memo.Lines.Add('5^(3^2) = '+FloatToStrF(Power(5,Power(3,2)),ffNumber,18,0));
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
5^3^2 = 1,953,125
(5^3)^2 = 15,625
5^(3^2) = 1,953,125
 
</pre>
 
=={{header|Dart}}==
<syntaxhighlight lang="dart">import 'dart:math' show pow;
 
void main() {
print('(5 ^ 3) ^ 2 = ${pow(pow(5, 3), 2)}');
print('5 ^ (3 ^ 2) = ${pow(5, (pow(3, 2)))}');
}</syntaxhighlight>
{{out}}
<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 519 ⟶ 643:
(5^3)^2 = 15625
5^(3^2) = 1953125
</pre>
 
=={{header|FutureBasic}}==
FB is translated into C which does not have an exponentiation operator. The caret operator '^' performs xor bitwise operation. FB also has an fn pow function, translated from the the standard C Math library, which takes two arguments.
<syntaxhighlight lang="futurebasic">
print "(5^3)^2 = "; (5^3)^2
print "5^(3^2) = "; 5^(3^2)
print
print "fn pow( fn pow(5,3), 2 ) = "; fn pow( fn pow(5,3), 2 )
print "fn pow( 5, fn pow(3,2 ) ) = "; fn pow( 5, fn pow(3,2 ) )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
(5^3)^2 = 15625
5^(3^2) = 1953125
 
fn pow( fn pow(5,3), 2 ) = 15625
fn pow( 5, fn pow(3,2 ) ) = 1953125
</pre>
 
Line 699 ⟶ 843:
-> {pow 5 {pow 3 2}}
</syntaxhighlight>
 
=={{header|langur}}==
<syntaxhighlight lang="langur">writeln " 5^3^2: ", 5^3^2
writeln "(5^3)^2: ", (5^3)^2
writeln "5^(3^2): ", 5^(3^2)
</syntaxhighlight>
 
{{out}}
<pre> 5^3^2: 1953125
(5^3)^2: 15625
5^(3^2): 1953125
</pre>
 
=={{header|Latitude}}==
Line 748 ⟶ 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 777 ⟶ 945:
=={{header|OCaml}}==
OCaml language has '**' as an exponentiation symbol for floating point integers
<syntaxhighlight lang="ocaml">
<OCaml code>
# 5. ** 3. ** 2. ;;
# 5. **( 3. ** 2.) ;;
#(5. ** 3. ) **2. ;;
</syntaxhighlight>
 
{{out}}
<pre>
Line 819 ⟶ 987:
15625
1953125
</pre>
 
 
=={{header|Picat}}==
<syntaxhighlight lang="picat">main =>
X = 5**3**2, Y = (5**3)**2, Z = 5**(3**2),
print("5**3**2 = "), println(X),
print("(5**3)**2 = "), println(Y),
print("5**(3**2) = "), print(Z).
</syntaxhighlight>
 
{{out}}
<pre>
5**3**2 = 1953125
(5**3)**2 = 15625
5**(3**2) = 1953125
</pre>
 
Line 1,051 ⟶ 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,077 ⟶ 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,272 ⟶ 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>
 
Line 1,285 ⟶ 1,498:
(5**3)**2 -> 15625
5**(3**2) -> 1953125
</pre>
 
=={{header|XPL0}}==
XPL0 doesn't have an exponentiation operator, but it does have a Pow intrinsic (in the 32-bit versions).
<syntaxhighlight lang "XPL0">[Format(1, 0);
Text(0, "5**3**2 = "); RlOut(0, Pow(5., Pow(3., 2.))); CrLf(0); \right associative
Text(0, "(5**3)**2 = "); RlOut(0, Pow(Pow(5., 3.), 2.)); CrLf(0);
Text(0, "5**(3**2) = "); RlOut(0, Pow(5., Pow(3., 2.))); CrLf(0);
]</syntaxhighlight>
{{out}}
<pre>
5**3**2 = 1953125
(5**3)**2 = 15625
5**(3**2) = 1953125
</pre>
 
9,479

edits