# Bizarre errata with ternaries and integer literals...

This topic is 2088 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

 ((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?

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. Edited by Andreas Jonsson

##### Share on other sites
 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 Edited by saejox

##### Share on other sites

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.

##### Share on other sites
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!