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 / Boolean operator does not work (V1.0.6.6)

Author
Message
calcyman
16
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 16th May 2008 21:40 Edited at: 16th May 2008 21:55
The NOT operator does not work as expected.
I would expect NOT 1 to return 0, and NOT 0 to return 1.

However, the code below demonstrates the error:

print (NOT (1))
print (NOT (0))
wait key

as it prints -1 and -2.

To illustrate my point further:

If NOT 1=1 then print "1 does not equal 1"
If NOT 1=2 then print "1 does not equal 2"
wait key

does not work either!

The optomist's right, The pessimist's right.
jinzai
17
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 16th May 2008 21:50 Edited at: 16th May 2008 21:56
Not really. NOT flips all bits, so NOT 1 is %11111111111111111111111111111110, or -2, and NOT 0 is %11111111111111111111111111111111, or -1
NOT is a 1's complement. To make it 2's complement, you then add 1 to the notted value.
calcyman
16
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 16th May 2008 21:56
Bitwise NOT should, boolean NOT shouldn't.

The optomist's right, The pessimist's right.
jinzai
17
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 16th May 2008 22:13 Edited at: 16th May 2008 22:16
Boolean NOT doesn't actually exist, what you are talking about is actually called negation (! in C). I agree that it is confusing in the help files that it shows both, and perhaps that is the error because they both do the same thing. One is a unary and the other is a binary (meaning it takes two values) operator, but the one you have shown is shown to produce the results you are expecting, and that is an error.

I want to be clear that I agree with you, but I also want to make the distinction that there is no boolean not, it is inherently a bitwise function. You get the results you want with && NOT:

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 16th May 2008 22:16
This has been discussed in the past. DBPro has no 'boolean' operations, they are all binary. For example, both || and OR are the same, they work on all the bits.

calcyman
16
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 17th May 2008 12:45
Yes, but the help files say:

Quote: "The NOT operator works using the following table. This operator is a unary operator and only requires a single right-side value:

NOT 0 = 1
NOT 1 = 0



BITWISE OPERATORS

Bitwise operators, unlike boolean operators work on all the bits of the specified variable or value. There are six bitwise operators as follows:

BITWISE LEFT SHIFT signified by the symbol will shift all bits one space to the left. %0111 1 becomes %1110.
BITWISE RIGHT SHIFT signified by the symbol >> will shift all bits one space to the right. %0111 >> 1 becomes %0011.
BITWISE AND signified by the symbol && will AND all bits of one value with another. %1111 && %0011 becomes %0011.
BITWISE OR signified by the symbol || will OR all bits of one value with another. %1111 || %0011 becomes %1111.
BITWISE XOR signified by the symbol ~~ will XOR all bits of one value with another. %1111 ~~ %0011 becomes %1100.
BITWISE NOT signified by the symbol .. will NOT all bits of the right value. %1111 .. %1010 becomes %0101.
You will discover how useful these operators become when writing conditions for your programs. Being able to write conditions with multiple parts will become increasingly
important as you begin to write more complex programs."


If you wanted bitwise NOT, you would use .. rather than NOT.
It also flaws basic logic statements, like this:

If NOT 1=1 then print "1 does not equal 1"
If NOT 1=2 then print "1 does not equal 2"
wait key


The optomist's right, The pessimist's right.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 17th May 2008 13:21 Edited at: 17th May 2008 13:33
Quote: "If you wanted bitwise NOT, you would use .. rather than NOT."

No, they are both the same. Just as OR and || are the same, and AND and && are the same.

Quote: "It also flaws basic logic statements, like this:

If NOT 1=1 then print "1 does not equal 1"
If NOT 1=2 then print "1 does not equal 2""

No it doesn't, because NOT is not used like that.

However, you can do this:



IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th May 2008 13:33
IIRC, Lee made a decision a while ago (during discussions much like this) to make the operators bitwise, not logical.

I thought it a shame, but there are other ways of getting logical operations despite that, and they are not hard.



If you look at the functions, you'll see that it's simple to convert a bitwise function to a logical function - I'm using the comparison operators to give me a 0 or 1 result and then using the bitwise operators on those.

Now, that all said, I do think that Lee should update the help files in line with his decision, so I'm going to confirm this report for that reason only.

pcRaider
16
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 17th May 2008 14:05
A compiler being different from helpfile in feeling uneasy about it.
And being contents misunderstanding.
Lee corrects a program
Or Lee corrects helpfile.
When a compiler is different from helpfile, I call it a bug.
Helpfile of a mistake snatches time of many people.

Login to post a reply

Server time is: 2024-05-23 20:17:28
Your offset time is: 2024-05-23 20:17:28