Maths problem - help!

Miscellaneous Forums/General Discussion/Maths problem - help!

Posting this in the general section because it isn't language-specific.

I think my caffeine levels are low, because the penny just isn't dropping with this one. I know its easy but I can't get it.

Imagine you have two numbers - any two numbers. For an example let's say 32, and 40. The first is always lower than the second.

32 represents 0%. 40 represents 100%. Therefore 50% is 36 (half way between).

With me so far?

I need a formula that will take any two floats I give to it, then return a float between 0 and 1 based on a third float, which is always somewhere between the first and second floats.

I.e. Using 32.0 and 40.0, I give it 38.0, it returns 0.75.

Note; I'm using whole numbers here to keep the examples simple. The values involved could be floats to any number of decimal places, so lookup tables and such are out of the question.

Never mind, done it.

Had to normalise everything down to zero and work it from there.

function Whatever( fTest, fLow, fHigh )
{
return ( fTest - fLow ) / ( fHigh - fLow );
}

damn...... 41 sec late lol

Dude, buy some more coffee if you get stuck on something like that again - or better still quit making games and start knitting ;-p

Dude, buy some more coffee if you get stuck on something like that again - or better still quit making games and start knitting ;-p
At least I managed to suss it before anybody else replied. :)

Dude? Lost your English accent already?

Hey man, I always say dude because I'm a hippy. Chill ;-p

Chillax to the max, compadre. Didn't you get the memo? We all talk like 80s cartoon characters now.


TO THE MAXX!

..what does DUDE mean really??

A dude is an inexperienced cowboy.

A dude is an inexperienced cowboy.
You might want to take that to a Brokeback Mountain forum.

Broke Back Mount 'him don't you mean :op

Hey man, I always say dude because I'm a hippy. Chill ;-p


Are you sure it has nothing to do with you now working/living in BC, Canada?

Are you sure it has nothing to do with you now working/living in BC, Canada?
Well I'm not actually there yet, should be in about a month though. Part of me is hippy anyway and part is hardcore efficient perfectionist - strange combo but it works.