zlacker

[parent] [thread] 1 comments
1. lebubu+(OP)[view] [source] 2024-01-17 09:02:24
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

replies(1): >>x1f604+TJ3
2. x1f604+TJ3[view] [source] 2024-01-18 09:01:29
>>lebubu+(OP)
Yes, you are correct, the faster clamp is incorrect because it does not return v when v is equal to lo and hi.
[go to top]