Host Engineering Forum

General Category => Do-more CPUs and Do-more Designer Software => Topic started by: amezcackle on November 03, 2015, 05:38:31 PM

Title: order of math operations
Post by: amezcackle 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

Title: Re: order of math operations
Post by: franji1 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)
Title: Re: order of math operations
Post by: amezcackle 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
Title: Re: order of math operations
Post by: Mike Nash 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.)
Title: Re: order of math operations
Post by: franji1 on November 04, 2015, 10:59:16 AM
which is 6 in decimal
Even worse!
Oops!  Getting closer!   ;D