zlacker

[parent] [thread] 1 comments
1. svanta+(OP)[view] [source] 2024-01-16 17:02:51
Sure, that was the point - min(max()) forces you to give explicit preference to lo or hi, whereas with clamp it's up to the std library. I trust my users to bend my software to their will, but I don't want different behavior on mac and windows (for example).
replies(1): >>dahart+B6
2. dahart+B6[view] [source] 2024-01-16 17:31:52
>>svanta+(OP)
Yeah, seems reasonable. I think the outer call wins, so min(max()) will always return lo for empty intervals, right? I didn’t know std::clamp() was undefined for empty intervals. It does seem like a good idea to try to guarantee the interval is valid instead of worrying about clamp… even with a guarantee, the answer might still surprise someone, since technically the problem is mathematically undefined and the guaranteed answer is wrong.
[go to top]