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.

Postby KristopherWindsor » Jun 09, 2007 23:29

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

Postby anonymous1337 » Jun 09, 2007 23:32

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: 6225
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Jun 10, 2007 0:09

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:

Postby KristopherWindsor » Jun 10, 2007 0:14

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

Postby stylin » Jun 10, 2007 1:11

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

Postby 1000101 » Jun 10, 2007 14:18

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

Postby toml_12953 » Jun 12, 2007 18:19

If fb !qb then could you say

NOT fb=qb

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

Postby anonymous1337 » Jun 12, 2007 18:28

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

Postby 1000101 » Jun 13, 2007 9:27

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

Postby HD_ » Jun 13, 2007 9:34

fb<>qb

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

Postby counting_pine » Jun 13, 2007 13:21

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

Postby 1000101 » Jun 13, 2007 16:06

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

Return to “General”

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Gunslinger and 2 guests