You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: