Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upUpdated clamp method #2335
Updated clamp method #2335
Conversation
Works properly now when min > max.
|
I think I would prefer if min > max then we either do nothing or the input is invalid and we throw an exception. If you are clamping a value to a range, it doesn't make sense to pass a min > max. |
|
I'd agree that passing a min which is greater than max is invalid input. |
|
Shall we check it and throw or leave it silent? |
|
I'd vote to check it and throw: earlier you fail, earlier you fix. |
|
My worry is someone relies on the behavior. If you pass a min > max then the function correctly returns false. It would actually be annoying to need to check for min > max if you wanted false back in that case. I guess my vote is that it isn't necessarily an error if min > max so we can leave the method as is. |
|
Fwiw, I'd say that |
|
Agreed. |
jacobrec commentedSep 14, 2014
Works properly now when min > max.