Translate a value to another value range

This is probably a very simple question for most of the smart guys here. I am looking for the best way to translate a value into another range.

Let’s say I have value (x) that can be in a range between 0 (min) and 500 (max).

Now I want to translate that value to a range of -1 and +1.

So if x=0 the result would be -1, x=500 it would be +1 and x=250 would be 0.

This can probably be done with something like Mathf.Lerp or InverseLerp but I can’t quite figure out how…

If you want to transform some range [a,b] into some range [c,d]:

Let x be a number with respect to the interval [a,b]. Normalize x:

x_n = (x - a) / (b - a); // x_n is with respect to the interval [0,1]

Using the normalized value x_n:

result = x_n * (d - c) + c;

It’s possible to combine the two steps above into one:

result = (x - a) / (b - a) * (d - c) + c;