On Thu, Aug 28, 2025, at 1:26 PM, Kyle Katarn wrote: > Hi, > > 2025-08-28 at 09:37, Tim Düsterhus <t...@bastelstu.be> wrote :
>> There's precedent in ext/random with the Randomizer::getFloat() method >> that takes a Random\IntervalBoundary enum to decide on the the >> interpretation of the boundary values. Translated to `clamp()` this >> could mean: >> >> $value = 1.0; >> clamp($value, 0.0, 1.0, IntervalBoundary::ClosedOpen); // >> 0.999999999999999888978 >> >> Best regards >> Tim Düsterhus > > Just my opinion but the function aims to provide an alternative to > min(max()) that would be: > - easier to read > - faster to execute > > If having many different behaviors depending on an option and so a lot > of if-else path complexity, then it will tend to defeat the second > goal. I would add it if there is a strong interest, otherwise I'd > rather stick to a minimalist implementation (like seen in most > languages where clamp() is available. I would also favor the minimalist/traditional/like-everyone-else approach. I wondered at first if open/closed boundaries made sense, but on consideration, that's not what clamp() traditionally does. It's just min/max shortcutting. So let's just do min/max shortcutting and move on with life. --Larry Garfield