Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
In excel =-1^2+1 returns 2 while =1-1^2 returns 0.
What calculation rule decides this? Apparently in the first -1 is interpreted as (-1), where in the second part - is interpreted as a substraction operator. =-(1)^2+1 also returns 2. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Scriptick wrote: In excel =-1^2+1 returns 2 while =1-1^2 returns 0. What calculation rule decides this? Apparently in the first -1 is interpreted as (-1), where in the second part - is interpreted as a substraction operator. =-(1)^2+1 also returns 2. I guess '-' is only interpreted as the unary operator if it's first in a statement, otherwise you have to put it and its operand inside parenthesis = (-1) for example... /impslayer |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Scriptick,
Read the Help on "The order in which Microsoft Excel performs operations in formulas": You will see the difference between -1 and 1-1. NickHK "Scriptick" wrote in message oups.com... In excel =-1^2+1 returns 2 while =1-1^2 returns 0. What calculation rule decides this? Apparently in the first -1 is interpreted as (-1), where in the second part - is interpreted as a substraction operator. =-(1)^2+1 also returns 2. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, exactly what I could not find myself.
However, when I repeat the calculations in the immediate window in the VBE both expressions -1^2+1 and 1-1^2 evaluate to 0. This is according to the help function ("The order in which Microsoft Excel performs operations in formulas", but then in the VBE help), but also confusing. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Scriptick skrev: Thanks, exactly what I could not find myself. However, when I repeat the calculations in the immediate window in the VBE both expressions -1^2+1 and 1-1^2 evaluate to 0. This is according to the help function ("The order in which Microsoft Excel performs operations in formulas", but then in the VBE help), but also confusing. Had no idea that the operator precedence order was different in the immediate window! Guess it comes from VB where (in VB6 anyway) ^ has higher precedence than the unary - operator. In Excel formulas it's the other way around. /impslayer, who should probably go quiet for a couple of years again |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Scriptick,
In the VBA help of "Operator Precedence", it states that Exponentiation (^) is higher than Negation (-); i.e. the opposite of Excel. In "^ Operator Example"; ........ MyValue = (-5) ^ 3 ' Returns -125. Note the barckets. So it seem you correct that Excel and VBA switch the order of precendence for these two. NickHK "Scriptick" wrote in message oups.com... Thanks, exactly what I could not find myself. However, when I repeat the calculations in the immediate window in the VBE both expressions -1^2+1 and 1-1^2 evaluate to 0. This is according to the help function ("The order in which Microsoft Excel performs operations in formulas", but then in the VBE help), but also confusing. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|