I'm trying to figure out if there is a proper or commonly accepted name for this particular function (f).

float clamp(float min, float max, float v)
    if (v < min) return min;
    else if (v > max) return max;
    else return v;

float f(float min, float max, float v)
    float t = (v - min) / (max - min);

    return clamp(0.0, 1.0, t);
  • 3
    $\begingroup$ Closest I can think of is Excel's "PERCENTRANK" function, though it doesn't do the clamping bit. Your f would be equivalent to PERCENTRANK([min, max], clip(min, max, f))... if Excel had a clip/clamp function. $\endgroup$
    – Patrick87
    Commented May 15, 2014 at 22:27
  • $\begingroup$ What does it do? $\endgroup$
    – Raphael
    Commented May 19, 2014 at 18:40

1 Answer 1


This is sometimes called "0-1 normalization" or "feature scaling".



The entire function f() is a Piecewise function, which consists of 3 domains, defined separately for

  1. v <= min
  2. v is between min and max, and
  3. v >= max.

The primary function is the normalization function when v is between min and max. The other two functions just limit the range or codomain of the function.

Piecewise functions are used often in mathematics to make the whole function continuous over a larger domain or to handle special cases like divide by zero, which the original poster might want to handle when min == max.

And what does the function do?
Creates a function f(x) where f(min) returns 0.0, f(max) returns 1.0, and f(v) rescales the input v from 0.0 to 1.0 linearly. Anything less than min maps to 0.0; anything more than max maps to 1.0.

One application of this is to calculate the percentile of a data samples (but from 0.0 to 1.0 vice 0 to 100).

  • 1
    $\begingroup$ Agreed, seems the closest. Of course, this suffers from the same minor criticism I left in the comments regarding the PERCENTRANK function: for it to work, it requires that v be between min and max, which is by default true when considering samples, but which is explicitly untrue of cmbassnet's question. $\endgroup$
    – Patrick87
    Commented May 16, 2014 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.