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.

DarkBASIC Professional Discussion / Logical expression -- non-Boolean response - Bug with DBPro?

Author
Message
The man
20
Years of Service
User Offline
Joined: 30th Jan 2006
Location:
Posted: 14th Oct 2012 20:37
Hello,

In the expression below results should be "1 & True" for the first statement and "0 & False" for the second statement, considering the logic operators included and order of precedence.

It works properly in Python and other programming languages.



However, the result in Dark Basic is -2 for the second statement.

So can anyone explain to me (including DBP developers) exactly what Dark Basic Professional is considering in the second statement, and why it isn't working properly?

Creating games without using such basic logic might be difficult.

-The man-
Michael P
20
Years of Service
User Offline
Joined: 6th Mar 2006
Location: London (UK)
Posted: 15th Oct 2012 12:28
0 = false
Anything non 0 is true, so -2 = true

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 15th Oct 2012 16:03
"not" (and all other supposedly "logical" operators) is a bitwise operator in DBPro, so in binary, you are doing "not %00000000000000000000000000000001" which equals "%11111111111111111111111111111110" which is -2 in decimal.

You can instead simply test if it equals zero:

"not x" would change to "(x=0)"

[b]
The man
20
Years of Service
User Offline
Joined: 30th Jan 2006
Location:
Posted: 15th Oct 2012 21:20
Quote: "You can instead simply test if it equals zero:

"not x" would change to "(x=0)""


I'm not sure if I understand that part, because if x is 0 (default), then not x would result as -1 (true).

But you are correct about the first part, 2's complement explains the values received:
http://en.wikipedia.org/wiki/Two%27s_complement

And if you say something like:


Then you will get the UNSIGNED value as in the table on that link.

So, for example, normally in DB if we write not true (not 1), we will get -2 (or false). But if we assign that result to a Boolean variable such as in the code above, we will get 254, which is the UNSIGNED value, and it is the same value as -2 as it can be seen in the Wikipedia table.

Anyways, I'm not sure how great all of this was explained in the Dark Basic Professional help file.

I bought Dark Basic lith, standard, and then professional many years ago.

And Boolean logic is simple to understand in languages such as Python and many other languages. But it is my fault, I did not yet learn binary conversion. If I had, I would probably understand this easily.

At least now I know what happens, and why it happens. Exactly how it happens I will still have to learn.

Thank you Diggsey for your comments and the binary expression that you mentioned.

-The man-
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 15th Oct 2012 23:59 Edited at: 16th Oct 2012 00:31
Isn't it that OR is a "+" operation, AND is a "*" operation?
So you get:

not (A or B)
not (A + B)
not (1 + 1)
not (2)
-2

If I remember my circuit logic courses I believe this is what is happening here.


NOPE!

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 16th Oct 2012 00:01 Edited at: 16th Oct 2012 00:03
No, the logical operators do not correspond to arithmetic ones, the only relationships between them are to do with things like operator associativity and distributivity, and even then there are not exact parallels between the two sets of operators.

[b]
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 16th Oct 2012 00:30
Quote: "No, the logical operators do not correspond to arithmetic ones, the only relationships between them are to do with things like operator associativity and distributivity, and even then there are not exact parallels between the two sets of operators."


I wouldn't doubt it.
I did just test it only works like I said part of the time.

What you said made sense completely from the binary perspective.

Login to post a reply

Server time is: 2026-07-07 07:57:42
Your offset time is: 2026-07-07 07:57:42