2

Is there a name for function $f(x)=\max(a, \min(x, b))$, where $a \leq b$?
What actually this function does: it keeps value in bounds of $[a, b]$.

  • I only used this when checking if the number was between -MAX_INT and MAX_INT. Probably, this does not have a name unless you name it yourself .. :). – VIVID Jan 18 '21 at 13:55
  • I named and programmed it as opt(x,a,b)=..., and mostly use it to avoid IOOBE while accessing arrays, but for years I have doubts about name, and now have enough courage to ask question here :D – æ-ra-code Jan 18 '21 at 14:06
  • 2
    Is is called “clamp” in C++: https://en.cppreference.com/w/cpp/algorithm/clamp, and also here: https://en.wikipedia.org/wiki/Clamping_(graphics) – Martin R Jan 18 '21 at 14:10
  • Yes, this, thank you. I was sure that I already know about that, but for some reason nothing than "clip/clipping" sounds in my brain each time I tried to recall it. Please, post this as an answer, so I can nicely accept it. Or what should I do in this case if I don't need answers anymore? – æ-ra-code Jan 18 '21 at 14:15
  • On the interval [a,b] it's just f(x)=x. So on the interval [a,b] it's a straight line. –  Jan 18 '21 at 14:33
  • Yes, but $\exists x, x \notin [a, b]$. This answer describes how line looks for all cases. – æ-ra-code Jan 18 '21 at 14:43
  • 1
    In some contexts "clipping" might be the correct term for what the function does. Also see https://math.stackexchange.com/questions/1336636/is-clamp-a-formally-recognized-mathematical-function – David K Jan 18 '21 at 14:57

2 Answers2

2

Is is called “clamp” in the C++ standard library, and also in the OpenGL graphics library.

References:

Martin R
  • 113,040
  • Thanks for answer! Looks like I choose wrong StackExchange site to ask question, heh? But this is how I saw this question (in terms of min/max) despite it originally comes from programming area. But also answer is from that area.... hmmm... – æ-ra-code Jan 18 '21 at 14:30
1

I don't think there is any official "name" for this function. It is just a fancy way to express a piecewise linear function. It is very likely that people write it in such a compact way for a purpose of programming.

When $a=1$ and $b=4$, the graph of the function:

enter image description here