Hi All,
I know that general convention is
multiplication and division
before
addition and subtraction
and the PBP manual states this as..
PicBasic Pro Compiler performs all math operations in full hierarchal order. This means that there is precedence to the operators. Multiplies and divides are performed before adds and subtracts, for example. To ensure the operations are carried out in the order you would like, use parenthesis to group the operations
But does this mean that....
ALL Multiplication is done before ANY Division
ALL Addition is done before ANY Subtraction
eg
30*4-6+18/2+6*6 would be evaluated as follows
Multiplication
30*4-6+18/2+6*6
120-6+18/2+36
Division
120-6+18/2+36
120-6+9+36
Addition
120-6+9+36
120-51
Subtraction
120-51
69
... or do Multipy and divide have equal precedence and likewise addition and subtraction in which case the above would be done as
Multiply and Divide
30*4-6+18/2+6*6
120-6+9+36
Addition and Subtraction
120-6+9+36
69
I realise that in both cases the answer works out to be the same and that parts of a calculation can be forced to happen earlier by the use of brackets but I am wondering which if the above is the way it is done as it has a bearing on overflows. eg.
***// as opposed to */*/*
or
+++-- as opposed to +--++
could result in a number overflow before you get to any division or subtraction.
I need a definative answer as I am trying to create an Excel spreadsheet to find out at which point Melanies RTC code will overflow.
Bookmarks