[slscripters] A question of equality

1 view
Skip to first unread message

Chloe Constantine

unread,
Jan 20, 2012, 2:34:18 PM1/20/12
to secondlif...@lists.secondlife.com
Does anyone know if the not equals operator evaluates to TRUE when comparing two integers when the integers are different? I am concerned that it might evaluate to some non zero integer in which case I couldn't use

if (a ^ (b != c)) ...

as a test where a is guaranteed to be either TRUE or FALSE.

Any insight would be appreciated.

Thanks
Chloe

Corvan Nansen

unread,
Jan 20, 2012, 2:42:50 PM1/20/12
to Chloe Constantine, secondlif...@lists.secondlife.com
Hi there,

Generally speaking I would not depend on the particular value for true/false from comparison operators. Usually, Zero is considered to be False, and non-Zero to be True.

In LSL, I'm not aware of the language specifying the precise result of inequality, and in fact were I implementing it, I'd seriously consider simply doing an XOR operation.

Since TRUE and FALSE are simply constant integers, why not:

if ((a == TRUE) || (a == FALSE)) ...

for your test? Yes, you end up executing a couple more bytecodes, but you are certain that you're actually testing what you want to test, the code is more readable and hence more easily maintained, in the long run, it's better code (IMHO).

Cheers,
Corvan.

> _______________________________________________
> Click here to unsubscribe or manage your list subscription:
> https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters

_______________________________________________
Click here to unsubscribe or manage your list subscription:
https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters

Chloe Constantine

unread,
Jan 20, 2012, 3:39:27 PM1/20/12
to Corvan Nansen, secondlif...@lists.secondlife.com
As it happens, on further investigation, I only care if b is or is not equal to 0, and since that is already FALSE I can use appropriate logical operators as a will always be TRUE or FALSE.

As for the few extra bytecodes... I sometimes push the limits so I like to be as efficient as possible both in size and speed. It's a style that discourages other people from meddling in the script :)

Thanks for the suggestion, though.
Chloe

Nox Ferocia

unread,
Jan 20, 2012, 9:30:46 PM1/20/12
to secondlif...@lists.secondlife.com
> Date: Fri, 20 Jan 2012 14:34:18 -0500
> From: Chloe Constantine <chloe1982....@gmail.com>
> Subject: [slscripters] A question of equality

>
> Does anyone know if the not equals operator evaluates to TRUE when
> comparing two integers when the integers are different? I am concerned that
> it might evaluate to some non zero integer in which case I couldn't use
>
> if (a ^ (b != c)) ...
>
> as a test where a is guaranteed to be either TRUE or FALSE.
>
> Any insight would be appreciated.
>
> Thanks
> Chloe

in the case of '(A != B)' the result will be '0' or '1' unless 'A' and
'B' are lists, in which case the result will be '(llGetListLength( A )
- llGetListLength( B ))'. if you are truly worried about the return
from the operation, you can prefix it with '!!' to force reduction to
'0' or '1'

Reply all
Reply to author
Forward
0 new messages