## Not operator should work like a Function, not like this.

General FreeBASIC programming questions.
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:

### Not operator should work like a Function, not like this.

In the line ? 5 - (Not(0) * 10), FB is calculating ((0) * 10) before applying the Not. Shouldn't Not(0) be calculated, and then multiplied by ten? I'm not sure how QB handles this.

Code: Select all

`? Not(0) '-1'these should all be the same, but I get 15, 6, 15? 5 - (-1 * 10)? 5 - (Not(0) * 10)? 5 - ((Not(0)) * 10)Sleep`
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California
I don't see why not should be handled as a function.

Putting parenthesis after what isn't a function does not (pun!) turn it into a function. Parenthesis just change the operations precedence, so all examples you gave are giving the correct output.

0 * 10 I believe, takes precedence before NOT, so it's (NOT ( (0) * 10 )). 5 - -1 = 6.
counting_pine
Posts: 6225
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs
Basically, Not isn't a function. You don't need to use brackets with it.
You can write:

Code: Select all

`if not(a = 10) then`

But you can also just write:

Code: Select all

`if not a = 10 then`

which perhaps looks a bit cleaner, and it gives you a better idea of what Not is really doing.

Here's a question to get you thinking:
How would you expect the following If statement to behave?

Code: Select all

`if not (a + b) = 10 then`
KristopherWindsor
Posts: 2428
Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:
Okay, I got confused. :-| I thought Not doubled as a Function if it was followed by parenthesis. I supposed Not (a + b) = 10 would be calculated as Not ((((a + b) = 10))), with Not applied lastly. :-)
stylin
Posts: 1253
Joined: Nov 06, 2005 5:19
OPERATOR NOT is pretty low in the order of operation. Here's an incomplete list, missing the assignment, indexing, UDT, pointer and memory operators:

http://www.freebasic.net/wiki/wikka.php ... Precedence
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
If you want it to do the not first, then put the entire operation in brackets, not the value it's working on.

Code: Select all

`? 5 - ( ( Not 0 ) * 10 )`

btw, QB handles it the exact same way. Irregardless of that, fb !qb
toml_12953
Posts: 27
Joined: Jul 07, 2005 12:37
Location: Malone, NY
Contact:

### Not Operator

If fb !qb then could you say

NOT fb=qb

?
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California
Probably, toml :P
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
toml, it would be more accurate to say, fb = Not QB.
HD_
Posts: 215
Joined: Jun 10, 2006 12:15
Contact:
fb<>qb

simple.
counting_pine
Posts: 6225
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs
1000101 wrote:toml, it would be more accurate to say, fb = Not QB.
Only in the same way that it would be more accurate to say 2 = Not 3.
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14