General FreeBASIC programming questions.
KristopherWindsor
Posts: 2428 Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:
Post
by 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
Post
by 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: 6323 Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs
Post
by 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:
But you can also just write:
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?
KristopherWindsor
Posts: 2428 Joined: Jul 19, 2006 19:17
Location: Sunnyvale, CA
Contact:
Post
by 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. :-)
1000101
Posts: 2556 Joined: Jun 13, 2005 23:14
Location: SK, Canada
Post
by 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.
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:
Post
by toml_12953 » Jun 12, 2007 18:19
If fb !qb then could you say
NOT fb=qb
?
1000101
Posts: 2556 Joined: Jun 13, 2005 23:14
Location: SK, Canada
Post
by 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:
Post
by HD_ » Jun 13, 2007 9:34
fb<>qb
simple.
counting_pine
Site Admin
Posts: 6323 Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs
Post
by 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
Post
by 1000101 » Jun 13, 2007 16:06
Since I was saying "fb is not qb" when I said "fb !qb", your assessment is correct.