As a programmer I often want to test something or vary it with a specific range. For example, it is very useful to me that I can test a variable in a way with sine such as:
variable_to_be_tested = 1/2 + (1/2) * sin ( variable_I_control_with_mouse )
This is because I know that variable_to_be_tested will only reach values between 0 and 1, and this may be very useful if it's important that that variable does not go outside of that range.
This one has two features that may be undesirable, however: 1) it will actually reach the values of 0 and 1 which might not be desirable and 2) being periodic may be useless or annoying to me.
Thus I set out to find other functions that may be highly useful to me. I found this one that solves the 2 problems above (it ranges from 0 to 1 but will never actually reach them and is not periodic).
f(x) = ( (PI / 2) + atan(x) ) / PI
I also considered the exponential function and geometric series with finite sums. Performance is also a concern.
I have a few questions.
1) is there a name for this kind of technique of listing out families of functions that output certain ranges? (if there is I want to use it to search for more information and ideas).
2) Can anyone think of other functions that would be useful? After the functions that I've listed, I can't think of anything.
3) Can anyone comment/give advice on performance-related information about this stuff? For example, maybe using some trick with geometric series would generally be more performant on most systems compared to atan?
4) Does anyone else have similar experiences of needing to search for a function that had convenient behavior for a specific application that led them to more difficult and complicated functions?
There are many ways to do this and I'm not sure how fast each one is, but I can give you a few examples for inspiration. The sigmoid function is a very common example of a non-periodic function with range $(0, 1)$. You can scale/translate this however you'd like by multiplying by a constant and adding a constant to get a range of $(a, b)$. You can take a simple function like $\pm x^2+b$ to give you a range of $[b, \infty)$ or $(-\infty, b]$. To get $(a,\infty)$ or $(-\infty, a)$, you can try $\pm \frac{1}{x} + a$. The Wikipedia link I provided for the sigmoid function also has links to other similar functions.
I will add that, depending on your needs, you might not necessarily need these fancy functions if you just want a bound for your numbers. You can use the max() or min() functions (may also be called ceil() and floor()) in your programming language along with the simplest $x$ function. If this satisfies your needs, this is likely the fastest solution. If you are worried about reaching 0 or 1 and aren't too picky about how close you'll get, you can set the min and max values to be something like 0.00001 and 0.99999.