Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_Unsigned _Bit discrepancy #50

Open
FirbleMan opened this issue Mar 26, 2023 · 0 comments
Open

_Unsigned _Bit discrepancy #50

FirbleMan opened this issue Mar 26, 2023 · 0 comments

Comments

@FirbleMan
Copy link

When doing calculations with _Unsigned _Bits, if the number goes negative, QB64 acts inconsistent from how it acts with _Unsigned _Integers.
Whether this is intentional or not, I don't know. However, it appears to me like a bug.

Run the program at the bottom to see what I mean.
Running an _Unsigned _Bit and and _Unsigned _Integer, set to the same value, through the same calculation, yield vastly different results!
Normally QB64 does a sound job of returning a result in the form of the least common denominator variable type. For example, in the calculation, "3 / 2" a "1.5" would be returned. Or another example, "2 - 3" would return -1. Exceptions to this are when the calculation is assigned to a variable. Then the assigned variable's type is used. This is expected behavior.

Now consider the _Unsigned _bit:
In equations resulting in a decimal, nothing unusual happens.
But when things turn negative...
The rules of _Unsigned _Integer variable type seems to be used. That doesn't seem quite right.
For example, "0 - a" where a is dimensioned as _Unsigned _Bit, 4294967295 is returned. Which is -1 for _Unsigned _Integers
Shouldn't, at the very least, _Unsigned _Bit rules of calculation be used, so it would return the top value given the amount of bits dimmensioned?
However, try the same equation with an _Unsigned _Integer, and you get -1!
I believe the way _Unsigned _Integers work is the way _Unsigned _Bits should as well.

Dim UnsignedBIT As _Unsigned _Bit
Dim UnsignedINT As _Unsigned Integer
Dim SignedINT As Integer

UnsignedBIT = 1
UnsignedINT = 1

Print "UnsignedBIT = "; UnsignedBIT;
Print "UnsignedINT = "; UnsignedINT
Print ""
Print "Unsigned bit does not act like unsigned Integer."
Print "-UnsignedBIT = "; -UnsignedBIT
Print "-UnsignedINT = "; -UnsignedINT
Print "0 - UnsignedBIT = "; 0 - UnsignedBIT
Print "0 - UnsignedINT = "; 0 - UnsignedINT
Print ""
Print "Saving to a signed bit works as expected."
SignedINT = -UnsignedBIT
Print "SignedINT = -UnsignedBIT"; SignedINT;
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant