The documentation of clamp claims that:
clamp(x, lo, hi)
Return x if lo <= x <= hi. If x < lo, return lo. If x > hi, return hi. Arguments are promoted to a common type.
However clamp(8,10,6) returns 6. From the documentation I expect that the check x < lo is performed first, in which case the return should be 10.
Note that enforcing lo <= hi was considered and rejected in #8006. Seems like just swapping those two clauses is sufficient here, yes?
I'm not sure. What is the expected behavior when lo > hi?
Just as you've observed it. I'm suggesting re-arranging the last two if clauses in the documentation so it matches the current behavior:
Return x if lo <= x <= hi. If x > hi, return hi. If x < lo, return lo.
Most helpful comment
Just as you've observed it. I'm suggesting re-arranging the last two if clauses in the documentation so it matches the current behavior: