[Gambas-user] Issue 195 in gambas: The bit manipulation functions does not work correctly on Shorts when negative values are returned

gambas at ...2524... gambas at ...2524...
Thu Jan 19 01:26:26 CET 2012


Status: New
Owner: ----
Labels: Version Type-Bug Priority-Medium OpSys-Any Dist-Any Arch-Any  
Desktop-Any GUI-Any

New issue 195 by emil.len... at ...626...: The bit manipulation functions does  
not work correctly on Shorts when negative values are returned
http://code.google.com/p/gambas/issues/detail?id=195

1) Describe the problem.
The bit manipulation functions at http://gambasdoc.org/help/cat/bit?v3 does  
not work correctly when negative Shorts are returned.
If, for example, the return value should be -1, it actually returns a Short  
with the value 65535 (which is outside the Short range!).

2) GIVE THE FOLLOWING INFORMATIONS (if they are appropriate):

Version: TRUNK
Revision: r4404

3) Provide a little project that reproduces the bug or the crash.
Print Asr(CShort(-4), 1) '=> 65534
Print BSet(CShort(-2), 0) '=> 65535
Print Ror(CShort(1), 1) '=> 32768
Print Shl(CShort(-1), 0) '=> 65535

And a little tip for the Shr/Asr implementation:
Are this kind of code really needed?
val = (((int)val >> bit) & 0x7FFFFFFF) | (((int)val) & 0x80000000);
Wouldn't it be enough with:
val = ((int)val >> bit);
since >> with signed datatypes in C already keeps the sign?





More information about the User mailing list