5 ms·
Yes, I arrived at the same conclusion. The various code snippets in the article don't compute the same "function". The order between the min() and max() matter
by lebubule 3y ago
Yes, I arrived at the same conclusion.
The various code snippets in the article don't compute the same "function".
The order between the min() and max() matters even when done "by hand".
This is apparent when min is greater than max as the results differ in the choice of the boundaries.
Funny that for such simple functions the discussion can become quickly so difficult/interesting.
Some toying around with the various implementations in C [1]:
[1]: https://godbolt.org/z/d4Tcdojx3 https://godbolt.org/z/d4Tcdojx3
- x1f604 3y agoYes, you are correct, the faster clamp is incorrect because it does not return v when v is equal to lo and hi.