math.h
goes to the trouble of providing min
and max
, but not a clamp function. I would have thought that as they are all usually similar implementation-wise they would all appear in the same library.
Is there any particular reason that math.h
does not feature a clamp function|macro?
Is it that the creators of math.h
did not deem it necessary or did they just not think about it?
EDIT: It seems people are missing the point here. I'm not asking why didn't they add clamp because I'm lazy and don't like writing a new clamp - quite the opposite, I hardly ever use it (though admittedly I use it more than I use some of the standard libraries).
What I'm asking is "does anyone know of any reason why the c++ standardisation authorities or creators or whoever chose not to include a clamp function in math.h
?".
I am by no means complaining that it is not in math.h
, I am merely asking "is there a good reason it isn't there?".
EDIT:
I am explicitly not asking how to write a clamp()
function.
#define
us part of your mix/max, you did it wrong. – Threescoreclamp
multiple times, it would be nice to have, – Dovelikealgorithms
usemin
might also have something to do with it the inclusion. – Threescoreclamp()
- GTK+ GLib hasCLAMP()
. And I always#define
it. But it would be better if it were standardized. – Prepotency