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 / 'and', 'xor' and 'not' are binary, not logical

Author
Message
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 2nd Oct 2008 23:02
In DBPro, the operators AND, XOR and NOT are binary, when the help file specifically says that they are logical, and has separate entries for the binary equivalents.



Both 1 and 2 are non-zero, so a logical AND should return 1
2 is non-zero, so a logical NOT should return 0
Both 1 and 2 are non-zero, so a logical XOR should return 0

[b]Yuor signutare was aresed by a deslyxic mud...
BOX2D V2 HAS HELP FILES! AND A WIKI!
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
calcyman
16
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 3rd Oct 2008 17:49
The AND/OR operators work equally well as boolean (logical) operators, it's only the NOT operator which has a difference.

Note that with boolean operators you should only use 1 and 0 (true and false) as an input.

I agree that the help files are in error, as they explicitly state:

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"


But for some reason AND behaves like &&, OR behaves like || and NOT behaves like ..

The easiest way of fixing it is to do the following:

function logicalNOT(a as boolean)

a = 1 - a

endfunction a

Even though there's still a workaround, it's one of the most commonplace bugs in DBPro, and should be fixed.

The optomist's right, The pessimist's right.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd Oct 2008 19:10
@WindowsKiller
Well it's not exactly a big deal to replace 'and' with '&&' and 'not' with '..'
All the operators have bitwise versions, so why not use them??? I doubt there are many places where people require the bitwise ones anyway! I have NEVER used them for it, and I have never ever seen them used for bitwise operations in a single piece of code, so I think your statement
Quote: "it would break almost every piece of code ever written for DBPro so far"
is a great exageration!

[b]Yuor signutare was aresed by a deslyxic mud...
BOX2D V2 HAS HELP FILES! AND A WIKI!
calcyman
16
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 3rd Oct 2008 22:33
Whenever I use bitwise operations (e.g. for extracting individual bits out of a dword), I always use && rather than AND.

But WindowsKiller does have a point - there are some pieces of code that rely on using the "logical" operators as bitwise ones.

They should definitely change the help files, as anyone who uses the poor documentation will be left with a piece of code that doesn't work properly, through no fault of their own.

The optomist's right, The pessimist's right.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 4th Oct 2008 12:24
@WindowsKiller
I meant where they have used 'and' instead of '&&', etc. Since the help files say that '&&' is bitwise, not 'and', every piece of code I have seen, always uses '&&' for the bitwise ones. Yes there are some pieces of code that use the logical ones, but these are so few it would be a simple matter to switch over.
If you really feel it would break too much code, maybe it would be an idea to have an option in the compiler options whether or not to tread 'and', 'or and 'not' as bitwise or logical.

[b]Yuor signutare was aresed by a deslyxic mud...
BOX2D V2 HAS HELP FILES! AND A WIKI!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Oct 2008 01:05
@WindowsKiller

Quote: "It's not. We are talking about changing the behaviour of an operator after all. Such a change would be a stupid move, really."


What do you mean? The switch to a bitwise calculation was just such a move. Why is one stupid and not the other?

In fact, if you took the trouble to search you'd find that the switch to bitwise calculation DID break a lot of people's code - although I agree it should be easy to fix the code when that happens.

As others have said, it's the Help file that's unhelpful - it really ought to be routine for Lee to check and amend the helpfile whenever functionality is changed. [Lee, are you there?]

I suspect this issue goes back to upgrade 6.0 where the upgrade text file says, rather obscurely,

Quote: " * The NOT condition operator no longer operates on the first bit. It acts in reverse of IF X, so X=0 is true, else false. Conditional operator ONLY!"

Login to post a reply

Server time is: 2024-05-05 00:48:59
Your offset time is: 2024-05-05 00:48:59