QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: xra7en on December 29, 2018, 10:54:08 am
-
does multiplication still processed before addition and subtraction?
-
prints "8", so multiplication comes first.
The code snippet you edited out didn't provide much information, so I can only guess that some variable isn't being passed to it correctly. Add a printout of the active variables and if statement equations to the error message to see if you can isolate anything going wrong, I guess?
-
after a second look I do not think it is a logic issue as it is where I am placing the operators to check, I need to rearrange the if/then/else
normally I do not have to use parentheses as the logic order works fine.
-
Unless documented otherwise, you should always assume - in any language - that the order of evaluation is as follows:
1. Parentheses (grouping)
2. Function Calls
3. Negation (Unary -)
3. Exponentiation (if available, e.g., FORTRAN **)
4. Multiplication and Division (left to right)
5. Addition and Subtraction (left to right)
Note that, for example, APL explicitly documents that evaluation is strictly right-to-left, not hierarchical.
-
Hi
IMHO() let us to manage the order of processing the math operation but we must remember the original order of processing operation
http://qb64.org/wiki/Mathematical_Operations#Basic.27s_Order_of_Operations (http://qb64.org/wiki/Mathematical_Operations#Basic.27s_Order_of_Operations)
here just an example
a = 10
b = 2
c = 3
PRINT "a="; a;
" b="; b;
" c="; c;
" d="; d;
" e="; e
PRINT "a - b * c= "; a
- b
* c;
" (a-b) * c=";
(a
- b
) * c
PRINT " a + b * c= "; a
+ b
* c;
" (a + b) * c= ";
(a
+ b
) * c
PRINT " a + b / c= "; a
+ b
/ c;
" (a + b) / c= ";
(a
+ b
) / c
PRINT " a + b MOD c= "; a
+ b
MOD c;
" (a + b) MOD c= ";
(a
+ b
) MOD c
PRINT " a MOD b * c= "; a
MOD b
* c;
" (a MOD b) * c= ";
(a
MOD b
) * c
PRINT "a ^ b *c="; a
^ b
* c;
"(a ^ b) *c=";
(a
^ b
) * c
PRINT "a ^ b *c="; a
^ b
* c;
"a ^ (b *c)="; a
^ (b
* c
)
I hope it will clear