Julia: clamp(8, 10, 6) is not consistent with documentation

Created on 19 Mar 2018  路  3Comments  路  Source: JuliaLang/julia

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.

doc

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:

Return x if lo <= x <= hi. If x > hi, return hi. If x < lo, return lo.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wilburtownsend picture wilburtownsend  路  3Comments

manor picture manor  路  3Comments

sbromberger picture sbromberger  路  3Comments

yurivish picture yurivish  路  3Comments

TotalVerb picture TotalVerb  路  3Comments