Operands priority

Everything else that doesn't fall into one of the other PB categories.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Operands priority

Post by Psychophanta »

Code: Select all

a.l=$aabbcc
e.l=$ffeedd
Debug Hex($FFFF&e|a)
Debug Hex(e|a&$FFFF)
Why I get different values?
Shouldn't be the same?
Bug?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

It seems the binary operators '&' and '|' have the same priority so i assume they just evaluate from left to right, the shift operators('<<' and '>>') however seems to have higher priority than the previously mentioned operators and are thus evaluated first..
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Pupil wrote:It seems the binary operators '&' and '|' have the same priority so i assume they just evaluate from left to right, the shift operators('<<' and '>>') however seems to have higher priority than the previously mentioned operators and are thus evaluated first..
But operators should NEVER be evaluated by position in expressions, but by type.
That's an ultra-BIG bug 8O
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Admin: Please move this Subject to Bug Reports section. :arrow:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Saboteur
Enthusiast
Enthusiast
Posts: 273
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Post by Saboteur »

But I think you have same problem in C. You must use parenthesis to avoid this. Or what do you want to evaluate first?
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Psychophanta wrote:
Pupil wrote:It seems the binary operators '&' and '|' have the same priority so i assume they just evaluate from left to right, the shift operators('<<' and '>>') however seems to have higher priority than the previously mentioned operators and are thus evaluated first..
But operators should NEVER be evaluated by position in expressions, but by type.
That's an ultra-BIG bug 8O
I think they behave in a logical way, i.e. as i expected them to evaluate, one thing i'm missing though, is a complete list in the manual of the priority order of the operators.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Saboteur wrote:But I think you have same problem in C. You must use parenthesis to avoid this. Or what do you want to evaluate first?
Same problem in C ?? Mmm... I'm not sure. If you say that...I didn't know it. However, i think AND operator should have priority over OR operator for logical expressions, and at least in the old Borland C++ there is like that.
Pupil wrote:one thing i'm missing though, is a complete list in the manual of the priority order of the operators.
Yes! Me too. :x
Last edited by Psychophanta on Sun Jan 23, 2005 9:54 pm, edited 1 time in total.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

hey psycho, i think the and should have priority above the or... actually, it doesn't matter, as long as it is properly documented!
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

There are common rules, just like * is higher than +
If any language would start using its own priorities, would be a big mess...
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Blade wrote:There are common rules, just like * is higher than +
If any language would start using its own priorities, would be a big mess...
Agree. :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

blueznl wrote:hey psycho, i think the and should have priority above the or... actually, it doesn't matter, as long as it is properly documented!
Well, yes, i think you're right, corrected my above post :oops:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply