Exponentiation order: Difference between revisions
(added a new Rosetta Code task (exponentiation order).) |
(→{{header|Perl 6}}: add entry) |
||
Line 21: | Line 21: | ||
* Mathworld entry [http://mathworld.wolfram.com/Exponentiation.html exponentiation] |
* Mathworld entry [http://mathworld.wolfram.com/Exponentiation.html exponentiation] |
||
<br><br> |
<br><br> |
||
=={{header|Perl 6}}== |
|||
<lang perl6>sub demo($x) { say " $x\t───► ", EVAL $x } |
|||
demo '5**3**2'; |
|||
demo '(5**3)**2'; |
|||
demo '5**(3**2)'; |
|||
demo '[**] 5,3,2'; |
|||
demo '[\**] 5,3,2';</lang> |
|||
{{out}} |
|||
<pre> 5**3**2 ───► 1953125 |
|||
(5**3)**2 ───► 15625 |
|||
5**(3**2) ───► 1953125 |
|||
[**] 5,3,2 ───► 1953125 |
|||
[\**] 5,3,2 ───► 2 9 1953125</pre> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |
Revision as of 16:51, 18 March 2014
This task will demonstrate the order of exponentiation (xy) when there are multiple exponents.
(Most languages usually support one of **, ^, or ↑ or somesuch.)
task requirements
Show the result of a language's evaluation of multiple exponentiation (either as an integer or floating point).
Use whatever exponentiation operator for your language; use a comment showing what the operator(s) is/are.
Using whatever operator or syntax your language supports (if any), show the results in three lines (with identification):
- 5**3**2
- (5**3)**2
- 5**(3**2)
If there are other methods (or formats) of multiple exponentiations, show them as well.
- See also
- Wiki entry exponentiation
- Mathworld entry exponentiation
Perl 6
<lang perl6>sub demo($x) { say " $x\t───► ", EVAL $x }
demo '5**3**2'; demo '(5**3)**2'; demo '5**(3**2)'; demo '[**] 5,3,2'; demo '[\**] 5,3,2';</lang>
- Output:
5**3**2 ───► 1953125 (5**3)**2 ───► 15625 5**(3**2) ───► 1953125 [**] 5,3,2 ───► 1953125 [\**] 5,3,2 ───► 2 9 1953125
REXX
<lang rexx>/*REXX program demonstrates various ways of multiple exponentiations. */ /*┌────────────────────────────────────────────────────────────────────┐
│ The REXX language uses ** for exponention. │ │ Also, * * can be used. │ └────────────────────────────────────────────────────────────────────┘*/
say ' 5**3**2 ───► ' 5**3**2 say ' (5**3)**2 ───► ' (5**3)**2 say ' 5**(3**2) ───► ' 5**(3**2)
/*stick a fork in it, we're done.*/</lang>
output
5**3**2 ───► 15625 (5**3)**2 ───► 15625 5**(3**2) ───► 1953125