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
_______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
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. On Jan 20, 2012, at 11:34 AM, Chloe Constantine wrote: > 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 > _______________________________________________ > 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 |
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 On Fri, Jan 20, 2012 at 2:42 PM, Corvan Nansen <[hidden email]> wrote: Hi there, _______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
In reply to this post by Chloe Constantine
> Date: Fri, 20 Jan 2012 14:34:18 -0500
> From: Chloe Constantine <[hidden email]> > 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' _______________________________________________ Click here to unsubscribe or manage your list subscription: https://lists.secondlife.com/cgi-bin/mailman/listinfo/secondlifescripters |
Free forum by Nabble | Edit this page |