Author Topic: Priority of operator in shapesheet - and ^  (Read 8275 times)

0 Members and 1 Guest are viewing this topic.

JuneTheSecond

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Priority of operator in shapesheet - and ^
« on: March 30, 2011, 02: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
Best Regards,

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

cliff50

  • Full Member
  • ***
  • Posts: 223
Re: Priority of operator in shapesheet - and ^
« Reply #1 on: March 30, 2011, 04:54:43 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
« Last Edit: March 30, 2011, 10:42:14 AM by Visio Guy »

vojo

  • Hero Member
  • *****
  • Posts: 1553
Re: Priority of operator in shapesheet - and ^
« Reply #2 on: March 30, 2011, 07:36:30 AM »
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
« Last Edit: March 30, 2011, 10:43:53 AM by Visio Guy »

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3947
  • Ideas Visio-lized into solutions
Re: Priority of operator in shapesheet - and ^
« Reply #3 on: March 30, 2011, 02:04:40 PM »
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

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Priority of operator in shapesheet - and ^
« Reply #4 on: March 30, 2011, 06:53:55 PM »
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

  • Full Member
  • ***
  • Posts: 223
Re: Priority of operator in shapesheet - and ^
« Reply #5 on: March 30, 2011, 09:52:11 PM »
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

  • Hero Member
  • *****
  • Posts: 1553
Re: Priority of operator in shapesheet - and ^
« Reply #6 on: March 30, 2011, 11:17:03 PM »
strictly speaking....visio violates the math law of PEMDAS

cliff50

  • Full Member
  • ***
  • Posts: 223
Re: Priority of operator in shapesheet - and ^
« Reply #7 on: March 31, 2011, 01:14:10 AM »
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

  • Hero Member
  • *****
  • Posts: 1061
Re: Priority of operator in shapesheet - and ^
« Reply #8 on: March 31, 2011, 01:27:54 AM »
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

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Priority of operator in shapesheet - and ^
« Reply #9 on: March 31, 2011, 04:30:55 PM »
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

  • Hero Member
  • *****
  • Posts: 1061
Re: Priority of operator in shapesheet - and ^
« Reply #10 on: March 31, 2011, 04:40:57 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

  • Hero Member
  • *****
  • Posts: 1027
    • Visio Shapes, Stencils and Sample Drawings
Re: Priority of operator in shapesheet - and ^
« Reply #11 on: March 31, 2011, 07:23:33 PM »
Thank you all spending time for my question.
Good night!
Best Regards,

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

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Priority of operator in shapesheet - and ^
« Reply #12 on: April 01, 2011, 06:11:58 AM »
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.