Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Bug Reports / DBP 7.4 - Using NOT operator with functions breaks logic

Author
Message
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 4th Oct 2009 07:12
Broken:



As you can see here, variables work just fine:

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Oct 2009 16:41
I agree - except that I think it is very unwise to use "not" that way since DBPro now uses bitwise "not" for some daft reason. [Why not have two "not" operators: one for simple Booleans and one for general bitwise "notting" of bytes, integers, etc? Then everyone is happy. ]

But this bug needs to be fixed.

The Help file is opaque on this as well:

Quote: "BOOLEAN OPERATORS

Simple Boolean operators provide the last type of operator. Dark Basic Professional allows you to use AND, OR, XOR and NOT operators on your data. Bear in mind that these operators are bitwise and are used when assembling a condition expression, such as:


IF a=1 AND b=2 THEN c=3
IF a=1 OR b=2 THEN c=3
IF a=1 XOR b=2 THEN c=3
IF NOT b=2 THEN c=3
"


What, for example, would be the value of c for different values of b in the last line of code? I can only find out by doing some experimenting.
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 4th Oct 2009 20:46
Quote: "I agree - except that I think it is very unwise to use "not" that way since DBPro now uses bitwise "not" for some daft reason."


I agree somewhat, although the expression I was using could only have been 0 or 1, so there would have been no problems.

Quote: "What, for example, would be the value of c for different values of b in the last line of code? I can only find out by doing some experimenting."


Not sure what you're asking, that last line of code looks pretty logical to me. The expression b=2 will result in 1 if it's equal, else 0. The NOT operator just inverts the result.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Oct 2009 00:53
Quote: "Not sure what you're asking"


I'm sure you're right, but unless you're familiar with the precedence of operators it isn't clear whether the expression evaluates as

(NOT b)=2

or

NOT (b=2)

which seem different to me. [For some odd reason I just can't remember the precedence of logical operators. ]

Quote: "although the expression I was using could only have been 0 or 1, so there would have been no problems"


Agreed. I guess the problem is how that value is represented. I would expect it to be cast as an integer before it's used in the IF statement but that doesn't seem to be the case.

Would the *.dbm file give a clue to what's going on?
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 5th Oct 2009 02:41 Edited at: 5th Oct 2009 02:41
Er wait what am I saying! If you perform a NOT operation on 1 it'll become 0xFFFFFFFE. Check out this code:



Apparently when you use NOT on variables in an if statement it acts as a boolean operator instead of binary, whereas functions (and variables and functions outside of IF statements) get the binary version. Thanks Lee, you've developed a very intuitive language here.
Dreamsenshi
16
Years of Service
User Offline
Joined: 4th Sep 2009
Location: USA
Posted: 5th Oct 2009 03:44
Quote: "[For some odd reason I just can't remember the precedence of logical operators. ]"


( ), NOT, AND, OR is the order.

* goes back to hiding *

Your error is my treasure. =^--^=
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Oct 2009 14:23
Benjamin

Could you remind us what the bug is exactly? Your most recent post seems to suggest you've changed your mind.
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 5th Oct 2009 15:40 Edited at: 5th Oct 2009 16:05
I'm not sure if it's a bug or just obscure behaviour:



Here's another example. Remember that SCREEN INVALID returns 1 the first time it's called (edit in a print statement at the start if you're not sure):



Compare the results with this which uses variables instead:



Er, remove the or in the function version of the code snippet and it works fine:



What on earth is going on?
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Oct 2009 20:28
This ought to be confirmed.

Users can justifiably expect a value returned by a function to be treated in the same way as the same value contained in a variable. If the value of interest is the result of a complicated comparison then the obvious thing to do is to put it all in a function and refer to it directly in the IF statement. But your examples show that that doesn't work.
Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 7th Oct 2009 21:02
DBPro just has the odd behaviour that 'not' on its own is bitwise, but 'if not' is like a special statement, and is boolean.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Oct 2009 00:03
Yes, but why is the value returned from a function treated differently from the same value contained in a variable?

Login to post a reply

Server time is: 2026-06-11 09:54:57
Your offset time is: 2026-06-11 09:54:57