Bizarre errata with ternaries and integer literals...

Started by
2 comments, last by cellulose 11 years, 10 months ago

((false?1:0)-(true?1:0))


This evaluates to 4294967295 (hex 0xFFFFFFFF), perhaps because the literals are being treated as unsigned. The expression (0-1) yields -1, though it's likely computed at compile time.

Is this a bug or a feature? tongue.png


Code that produced the issue:


//The white box soldiers on, knowing the fate of the world rests squarely on his shoulders.
heroPos.x += .005f*((Keyboard.right.held?1:0)-(Keyboard.left.held?1:0));
heroPos.y += .005f*((Keyboard.up.held?1:0) -(Keyboard.down.held?1:0));


Not a huge issue but a thing. The C++ programmer in me wishes AS booleans were math-friendly like their counterparts in native code, but I guess I can understand the reasons for avoiding that.


If I continue using this forum you'll notice my habit of striving for terse code borders on obsession. smile.png
Advertisement

int a = (false?1:0)-(true?1:0);
ConsoleOutput("a :" + a);



prints a: -1 for me.

edit:
ok. after reading your other post i see your issue.

even a simple if(1) does not compile in angelscript.
if accepts nothing but true or false.
i believe it would be a pain in the ass to implement such feature, and a feature that would confuse script writers

Is this a bug or feature?


Yes, it is because the numbers are considered unsigned. No, I do not consider it as a bug.

I do however recognize that interpreting the numbers as signed would be more intuitive. I'll consider changing the current behaviour.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Saejox:

Try
ConsoleOutput("a :" + ((false?1:0)-(true?1,0)));


I think defaulting to signed (in the C++ style) would generally be more intuitive. Again, thanks for the prompt response! :)

This topic is closed to new replies.

Advertisement