# Function to find the ratio of a reference value given a low and high limit

• Aug 18th 2010, 03:17 PM
gtzpower
Function to find the ratio of a reference value given a low and high limit
Hi all, I am just looking for the generic name of a mathematical function that will return the ratio of a reference value between a supplied low and high limit. This is probably best illustrated by example:

1st value is reference, second value is low, and third value is high
SomeFunction(5, 0, 10) = 0.5
SomeFunction(12, 10, 20) = 0.2
SomeFunction(40, 20, 40) = 1

Make sense?

Thanks!
• Aug 18th 2010, 03:30 PM
allsmiles
hmm i don't know what you want to me to?
any help? :)
• Aug 20th 2010, 03:18 AM
HallsofIvy
Well, it's not terribly clear! You seem to be saying that 5 is half way between 10 and 20, 12 is 0.2= 1/5 of the way between 10 and 20, and that 40 is all the way (1= 100%) between 20 and 40.

If that is correct then your "some function" is $f(x, y, z)= \frac{x- y}{z- y}$.

$f(5, 0, 10)= \frac{5- 0}{10- 0}= \frac{5}{10}= 0.5$
$f(12, 10, 20)= \frac{12- 10}{20-10}= \frac{2}{10}= 0.2$
$f(40, 20, 40)= \frac{40- 20}{40- 20}= \frac{20}{20}= 1$
• Aug 20th 2010, 09:36 AM
gtzpower
Thanks for the replies. Yes, HallsofIvy, you have pinpointed the function I am referring to. Sorry, I don't know math well enough to make it that clear (I could post my C++ code, but didn't know if that would confuse things further). I actually have the math behind the function figured out, but I don't know what to name it. I just assumed, with how much I use it, that there would be a proper mathematical name for it as I am sure many others have developed such a function.

In my use of it, I have named it RatioInRange(), but if there is an official name, I would prefer to use it so that others who make use of my library will recognize the function by name, assuming there is a proper name for it.

I also have a Blend() that reverses this by taking a ratio, a low and high, and converting it to a value in between the limits. I would like a proper name for this function too if there is one.

e.g. Blend(0.5, 0, 10) = 5