Function llClamp(integer val, integer min, integer max)
under review
Log In
SamanthaTekcat Resident
This really should be 'float llClamp(float val, float min, float max)'
Spidey Linden
under review
RestrainedRaptor Resident
And while we're at it, give us the damn ternary operator! Is there a ticket for that yet?
Woolfyy Resident
simple, less memory use and much quicker if existing in standard functions ... let's cross fingers and dream of such a feature existing for integer, float, vector and rot ... ouch ... LL ... please ...
Bleuhazenfurfle Resident
This should definitely be floats, if not both.
We do have llAbs and llFabs, so there is precedent for llClamp and llFclamp (despite how much I detest that naming scheme). It's an annoying function, yet one we need way too often.
Vincent Nacon
integer llClamp(integer Value, integer Max, integer Min){
return ((Value>Max)*Max) + ((Value<Min)*Min) + ((!(Value<Min)&&!(Value>Max))*Value);
}
Bleuhazenfurfle Resident
Vincent Nacon: Have you measured that code against simple if()s…? Such long-winded micro-optimisations generally rely on pipelining, which is almost never a consideration for evaluated bytecode (which is what I expect LSL to be), and you're doing several repeated comparisons there.
And I'd expect this to be better (8 operators vs. 11):
return Value + ((Value>Max)*(Max-Value)) + ((Value<Min)*(Min-Value));
Vincent Nacon
Bleuhazenfurfle Resident Yeah, it's generally better to have it done in one line process than doing it through if()s, but I like your formula better. Nice one. 👍
Kristy Aurelia
Both: integer and float versions would be ideal. Maybe even vector and rotation too.
Peter Stindberg
I assume you mean this: https://en.wikipedia.org/wiki/Clamping_(graphics) ?