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

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

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

Post by KristopherWindsor »

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

Post by anonymous1337 »

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
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

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:

Post by KristopherWindsor »

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

Post by stylin »

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
Location: SK, Canada

Post by 1000101 »

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

Post by toml_12953 »

If fb !qb then could you say

NOT fb=qb

?
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Post by anonymous1337 »

Probably, toml :P
1000101
Posts: 2556
Joined: Jun 13, 2005 23:14
Location: SK, Canada

Post by 1000101 »

toml, it would be more accurate to say, fb = Not QB.
HD_
Posts: 215
Joined: Jun 10, 2006 12:15
Contact:

Post by HD_ »

fb<>qb

simple.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

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
Location: SK, Canada

Post by 1000101 »

Since I was saying "fb is not qb" when I said "fb !qb", your assessment is correct.
Post Reply