Look at help. .a means ascii and stores values from 0 to 255. So, by saying b.a = 2 - 4 how do you expect to store and show you a negative value? It is like you want to store 1,000,000 in a byte. You just can't.Little John wrote:Who says so (except from you)?
I think the terms "signed" and "unsigned" apply when values are assigned to the respective variable, not when using it in calculations.
Unsigned variable bug
- doctorized
- Addict
- Posts: 854
- Joined: Fri Mar 27, 2009 9:41 am
- Location: Athens, Greece
Re: Unsigned variable bug
-
- Addict
- Posts: 4519
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Unsigned variable bug
I did not expect that.doctorized wrote:Look at help. .a means ascii and stores values from 0 to 255. So, by saying b.a = 2 - 4 how do you expect to store and show you a negative value?Little John wrote:Who says so (except from you)?
I think the terms "signed" and "unsigned" apply when values are assigned to the respective variable, not when using it in calculations.
You might want to read again what I wrote, and try to understand it in the given context.
Re: Unsigned variable bug
Hello UserRussian,User_Russian wrote:In this code a-4=254. But they are calculated as signed variables. Why?Code: Select all
a.a = 2 b.a = a-4 Debug b Debug Bool(a-4>0) If a-4>0 Debug "a>0" EndIf
here is my humble opinion:
"If cc" or "Bool(cc)" are on 32 or 64 range. Simply, there is no code source characters pair anymore to use CPU features. Fred took the choice to use the greatest bit as the sign status (CPU allows us to use carry flag, but Basic syntax should be overloaded, ie : a-b vs a--b, the first op with embedded sign, the second one with manual sign, it would be difficult to stay in simple syntax...)
Code: Select all
; Give -1 as it should give 1
Debug Hex((1 << 63) >> 63)
; give rightly 1
Debug Hex((1 << 62) >> 62)
These true bits have to be erased by a AND Mask during boolean op.
Code: Select all
Debug Bool(cc & $FF) ; for unsigned 8 bits
Debug Bool(cc & $FFFF) ; for unsigned 16 bits
Code: Select all
a.a = 2
b.a = a-4
Debug b
Debug Bool((a-4) & $FF>0)
If (a-4) & $FF >0
Debug "a>0"
EndIf
Re: Unsigned variable bug
Interesting subject which finds a way to the modules. Thank you.
If we change the default type, the comparison gives the respective result.Nota : Same way for procedures.
If we change the default type, the comparison gives the respective result.
Code: Select all
DeclareModule A
Declare Test()
EndDeclareModule
DeclareModule I
Declare Test()
EndDeclareModule
Module A
Procedure Test()
Define.A
A = 2
B = A - 4
If A < B
Debug Str(A) + " < " + Str(B)
Else
Debug Str(A) + " > " + Str(B)
EndIf
EndProcedure
EndModule
Module I
Procedure Test()
Define.I
A = 2
B = A - 4
If A < B
Debug Str(A) + " < " + Str(B)
Else
Debug Str(A) + " > " + Str(B)
EndIf
EndProcedure
EndModule
A::Test()
B::Test()
Code: Select all
Procedure Proc1()
Define.I
; ...
EndProcedure
Procedure Proc2()
Define.A
; ...
EndProcedure