News:

  • May 05, 2026, 09:29:43 AM

Login with username, password and session length

Author Topic: order of math operations  (Read 9854 times)

amezcackle

  • Newbie
  • *
  • Posts: 9
order of math operations
« on: November 03, 2015, 05:38:31 PM »
Is there a reason why designer performs multiplication before exponents in it's math operations? For example, an equation entered like this:

2 * 2 ^ 2

is rendered like this for a result of 16:

(2 * 2) ^ 2

Is it not usually performed like this for a result of 8?:

2 * (2 ^ 2)

Mike


franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: order of math operations
« Reply #1 on: November 03, 2015, 06:58:11 PM »
^ is XOR, not raised to power.  Do-more uses C/C++/C#/java syntax in its MATH expressions, so ^ is XOR.

However, those languages do not have a raised-to-power operator, so we stole one from the old BASIC language, ** (two asterisks).

So try 2 * 2 ** 2.  You will see the automagic placement of the parentheses as you expected:  2 * (2 ** 2)

amezcackle

  • Newbie
  • *
  • Posts: 9
Re: order of math operations
« Reply #2 on: November 03, 2015, 07:04:44 PM »
^ is XOR, not raised to power.  Do-more uses C/C++/C#/java syntax in its MATH expressions, so ^ is XOR.

However, those languages do not have a raised-to-power operator, so we stole one from the old BASIC language, ** (two asterisks).

So try 2 * 2 ** 2.  You will see the automagic placement of the parentheses as you expected:  2 * (2 ** 2)

Thanks, that's helpful.

Mike

Mike Nash

  • Hero Member
  • *****
  • Posts: 652
Re: order of math operations
« Reply #3 on: November 04, 2015, 10:27:54 AM »
So I had to check. I found (2*2)^2 is actually 6 in the Do-more, since in binary:

(010*010) XOR 010 = 100 XOR 010 = 110

which is 6 in decimal.

(I also noted * and ^ are easy to misread at 85% zoom in the ladder.)

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: order of math operations
« Reply #4 on: November 04, 2015, 10:59:16 AM »
which is 6 in decimal
Even worse!
Oops!  Getting closer!   ;D