Talk:Parsing/RPN to infix conversion: Difference between revisions

(→‎Negation: Spaces and the minus sign)
Line 39:
 
:In RPN the negative number has no space between the minus sign and the first digit. Subtraction as an operator has spaces around the sign. --[[User:Paddy3118|Paddy3118]] 16:06, 7 May 2012 (UTC)
:I agree that that describes the prn side, but the problem is on the infix side. Infix notation assigns a higer priority to exponentiation than to unary negation. If I use the perl implementation:
<pre>
>rpn.pl
-4 2 ^
-4^2
</pre>
:Then I use the generated infix in perl:
<pre>
>perl
print -5 ** 2
^Z
-25
</pre>
:The correct infix is (-5)**2. The same is true for infix in Ruby and Python:
<pre>
irb(main):001:0> -4 ** 2
=> -16
Python 3.2.2 (default, Sep 4 2011, 09:51:08) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> -4 ** 2
-16
</pre>--[[User:Nigel Galloway|Nigel Galloway]] 14:19, 11 May 2012 (UTC)
2,172

edits