Exponentiation with infix operators in (or operating on) the base: Difference between revisions
Content deleted Content added
Realize in F# |
Added Algol 68 |
||
Line 62: | Line 62: | ||
# [https://en.wikipedia.org/wiki/Order_of_operations#Programming_languages Wikipedia Order of operations in Programming languages] |
# [https://en.wikipedia.org/wiki/Order_of_operations#Programming_languages Wikipedia Order of operations in Programming languages] |
||
<br><br> |
<br><br> |
||
=={{header|ALGOL 68}}== |
|||
In Algol 68, all unary operators have a higher precedence than any binary operator. |
|||
<br>Algol 68 also allows UP and ^ for the exponentiation operator. |
|||
<lang algol68>BEGIN |
|||
# show the results of exponentiation and unary minus in various combinations # |
|||
FOR x FROM -5 BY 10 TO 5 DO |
|||
FOR p FROM 2 TO 3 DO |
|||
print( ( "x = ", whole( x, -2 ), " p = ", whole( p, 0 ) ) ); |
|||
print( ( " -x**p ", whole( -x**p, -4 ) ) ); |
|||
print( ( " -(x)**p ", whole( -(x)**p, -4 ) ) ); |
|||
print( ( " (-x)**p ", whole( (-x)**p, -4 ) ) ); |
|||
print( ( " -(x**p) ", whole( -(x**p), -4 ) ) ); |
|||
print( ( newline ) ); |
|||
OD |
|||
OD |
|||
END</lang> |
|||
{{out}} |
|||
<pre> |
|||
x = -5 p = 2 -x**p 25 -(x)**p 25 (-x)**p 25 -(x**p) -25 |
|||
x = -5 p = 3 -x**p 125 -(x)**p 125 (-x)**p 125 -(x**p) 125 |
|||
x = 5 p = 2 -x**p 25 -(x)**p 25 (-x)**p 25 -(x**p) -25 |
|||
x = 5 p = 3 -x**p -125 -(x)**p -125 (-x)**p -125 -(x**p) -125 |
|||
</pre> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
F# does not support the ** operator for integers but for floats: |
F# does not support the ** operator for integers but for floats: |
||
Line 71: | Line 95: | ||
-5.0**2.0=25.000000; -(5.0**2.0)=-25.000000 |
-5.0**2.0=25.000000; -(5.0**2.0)=-25.000000 |
||
</pre> |
</pre> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
<lang factor>USING: infix locals prettyprint sequences |
<lang factor>USING: infix locals prettyprint sequences |