Priority of operator in shapesheet - and ^

Started by JuneTheSecond, March 30, 2011, 07:52:52 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JuneTheSecond

In next shapesheet formulas Prop.Row_2 returns 4 but not -4,
because priority of minus sign is higher than power operator in shapesheet,
while minus sign is lower than power in VBA.
Would you please give me any suggestion about
how to think the merit of this hierarchy in shapesheet?


Prop.Row_1 = 2
Prop.Row_2 = -Prop.Row_1^2
Best Regards,

Junichi Yoda
http://june.minibird.jp/

cliff50

#1
Quote from: JuneTheSecond on March 30, 2011, 07:52:52 AM
In next shapesheet formulas Prop.Row_2 returns 4 but not -4,
because priority of minus sign is higher than power operator in shapesheet,
while minus sign is lower than power in VBA.
Would you please give me any suggestion about
how to think the merit of this hierarchy in shapesheet?
Prop.Row_1 = 2
Prop.Row_2 = -Prop.Row_1^2

Let me see if I understand this,you say in a ShapeSheet cell   -Prop.Row_1^2
is the same as saying (-2) ^2 = 4 -> negative raised to power 2 will return positive.
while VBA -(2^2)=-4-> the negative of a positive result within the brackets.
my thoughts are the ShapeSheet works the algorithm left to right in the absence of brkts

vojo

#2
yea....I bet Visio thinks you want to do this (-prop.row_1)^2   when you really want to do -(prop.row_1^2)

Although....I would say that PEMDAS would say raise the power first (E) then multiply by -1 (M)

interesting math anomally....wonder what else is lurking in the tool    ;D

wapperdude

I would say that Visio is doing it correctly in the shapesheet.

It is as Vojo suggests, -prop.row_1^2 is interpreted as (-prop.row_1)^2.  This issue is that Visio is taking the "-" as negative value of prop.row_1 and squaring it.   Visio is not multiplying prop.row_1 by "-1".  Hence, the operator priority issue of "-" vs "^" isn't a factor.

Proof:  make a 3rd row with the contents:  =-1*prop.row_1^2.  You will indeed get -4.

Wapperdude
Visio 2019 Pro

JuneTheSecond

Thank you, cliff50 and Vojo.
I agree the best practice may be to wrap formula
in brackets like -(prop.row_1^2), if I wish to get -4.
But I can't feel -2^2 = 4 is natural, can you?
I think there must be any reason to have such a
strange calculation order just in shapesheet.
Best Regards,

Junichi Yoda
http://june.minibird.jp/

cliff50

lol yes I agree it does seem strange that -2^2 = 4 ... you know,  some may even be brave enough to espouse -2 ^ 2 is indentical to -2 X -2 .. I recall a debate Ihad with mathematics years ago that if 3^2 = 3 X 3  then how come we cant describe a simple multiplication for 3 ^ 2.5  (by brave logic, three multiplied by itself two and a half times!!) ...  the actual syntax for powers such as N ^Y is -> take the log of N and then multiple by Y  and then take the antilog of the result ..

Cheers !

vojo

strictly speaking....visio violates the math law of PEMDAS

cliff50

ok lets test it   ->     heres the text as you see it   -2^2

who among us would pronounce it as

A) the negative, of two squared
or
B) negative two, squared

my vote is (B)

Ciao  ;)

Jumpy

I think the - operator is (imho rightfully so) treated differently, if it is the first element of a statement and in fron of a number then.
-2^2 is not the same as 0-2^2.

JuneTheSecond

Thank you, everybody.
Many guys seems prefer -2^2 = 4
But next VBA macro returns -4.
Would you hate VBA?

Sub test()
    MsgBox -2 ^ 2
End Sub
Best Regards,

Junichi Yoda
http://june.minibird.jp/

Jumpy

Quote from: JuneTheSecond on March 31, 2011, 09:30:55 PM
Would you hate VBA?

No. No. I don't know what is better 4 or -4, but I like 4 better, somehow.

But whatever it is, it should be a consistent behaviour in VBA and ShapeSheet and it is sad, that it isn't so.


As I guess, that you just started your day, while I go to bed now, I have a suggestion for you to test:

What is with Excel: How does Excel-VBA interpret this and how does calculating inside an Excel cell calculate this.

Just for sake of curiosity...


Good Night,
Jumpy

JuneTheSecond

Thank you all spending time for my question.
Good night!
Best Regards,

Junichi Yoda
http://june.minibird.jp/

Jumpy

Just made the test:

Excel-VBA: -4 (w.Cells(1,1).Value = -2^2 (where w was a worksheet object))

Excell-Cell: 4 (wrote in n cell: =-2^2)

So you can say, that Excel shows the same behaviour.