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.

AppGameKit Classic Chat / BUG: (MSB - Windows Version) Most Significant Bit Bug (Windows) Mac is correctly processed

Author
Message
Muckypaws
AGK Developer
13
Years of Service
User Offline
Joined: 21st Oct 2011
Location:
Posted: 27th Jan 2015 23:29
Hi,

I've found another Bug in AppGameKit 2.0.10 in the Windows version, works as expected on Mac and iOS not on Windows.

The program I'm creating needs to manipulate data at BIT level, and so I set the MSB in one of two ways

Either

MSB = -1

or

MSB = %10000000000000000000000000000000

So I couldn't work out why my program was behaving oddly on the Windows Platform when testing...

And it turns out the MSB is set to %1111111111111111111111111111111
(31 binary 1's)

Which is not what is explicitly set. I suspect the interpreter is interpreting differently on Windows.

Unfortunately I can not work around this bug given the way I'm manipulating data, not without significant rework.

Any news when the next patch release will be for AGK2?

Test it for yourself...




Kind Regards
Jason
www.wonkypix.com

http://www.wonkypix.com
http://www.appstore.com/jsecconsultancyltd
http://itunes.apple.com/us/app/newtons-nonsense/id473520354?ls=1&mt=8
paulrobson
10
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 28th Jan 2015 09:11
This isn't actually a bug, it's supposed to work this way. AppGameKit (oddly IMO) deals with out of range constants not by yelling at you for having an out of range constant, but by forcing it into the range of legal constants. Seriously.

So in 8 bit equivalent (range -128 .. 127) if you write



They will all set x to the same value , 127. Works similarly at the negative boundary.

So, your code. What you are actually doing with your binary is the same as



And the compiler is looking at this, thinking, ah, we don't do constants that big and helpfully changing it for you to 2147483647 !

Probably the best workround is to represent it as its actual value, e.g. -2147483648 (or 1 << 31) which seems to work because it's a legal 32 bit value. The latter works because AppGameKit does not handle constants with arithmetic as constants, so it evaluates this 1 << 31 value in code.

Personally I think this is slightly bonkers and I cannot see a reason not to change it so an illegal constant simply announces its an illegal constant. You end up with code like yours which is effectively the same as having the compiler change a = 3 to a = 2 for you.....
Muckypaws
AGK Developer
13
Years of Service
User Offline
Joined: 21st Oct 2011
Location:
Posted: 28th Jan 2015 11:19
Hi Paul,

Thanks for your explanation, I had worked that out, however my point here is that there is inconsistency with the MAC Interpreter and the Windows Interpreter.

So it's a bug on either system from your explanation.

On Mac, the Value is correctly set (at the BitWise Level) or incorrectly as per your explanation.

But windows, incorrectly (or correctly as per your explanation), applied the error correction.

Either way both platforms are mutually exclusive!

Ok, so the work around works on both platforms, thank you.

Additionally I note on windows platform, setting a variable with all bits set, i.e.



Because the ! function doesn't work correctly, resulting in a similar pattern

On MAC I get correctly set all 32 bits, on Windows only 31 bits are set with the MSB being cleared.

Workaround, and it's potso!



So the workaround will get me through the next part, but surely we should have the interpreter behave consistently across all platforms?

Kind Regards
Jason
www.muckypaws.com
www.wonkypix.com

http://www.wonkypix.com
http://www.appstore.com/jsecconsultancyltd
http://itunes.apple.com/us/app/newtons-nonsense/id473520354?ls=1&amp;amp;mt=8
paulrobson
10
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 28th Jan 2015 14:12
Absolutely. I suspect it's to do with how different compilers handle borderline cases. Do you want to put this on the bug tracker or shall I ?

One thing to note: AFAICS the #constant actually works like a macro -it's more like #define in C with no parameters. If this is time important, then it will calculate "ALLBITS" every time you use it, whereas if you put it in a variable ALLBITS it only does it once.
Muckypaws
AGK Developer
13
Years of Service
User Offline
Joined: 21st Oct 2011
Location:
Posted: 28th Jan 2015 15:52
Paul,

Thank you, that's interesting, I assumed (wrongly) that it would resolve at compile time rather than calculate each time. That's a good performance tip!

I'm trying to reduce the number of global variables, but I will go with this suggest thanks!

Bug Tracker?

Where can I find it?

Kind Regards
Jason

https://www.facebook.com/WonkyPix
http://www.wonkypix.com
http://www.appstore.com/jsecconsultancyltd
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Jan 2015 16:38
Quote: "the #constant actually works like a macro -it's more like #define in C with no parameters."


It's done at compile time. There's a sneaky way to work this out...

Replace a command with a constant. If it compiles, then it's done a Find&Replace at compile time. I ran a quick test



and it compiled

Quidquid latine dictum sit, altum sonatur
paulrobson
10
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 28th Jan 2015 17:23
Yes, it's a macro substitution AFAICS. But it doesn't optimise the macro, this is a bit of a shame as it allows you to have constants referring to other constants but they are optimised out as a single constant.

So if you put



it never simplifies it but does the math every time. Normally it doesn't matter, it might if you are doing a lot of bit operations.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Jan 2015 17:40
Ah, I understand.
So if it's a string replacement or a simple number then it is fully optimised. But anything more complex starts to become inefficient.

Quidquid latine dictum sit, altum sonatur

Login to post a reply

Server time is: 2024-11-25 17:32:09
Your offset time is: 2024-11-25 17:32:09