I honestly can't think of what to search for, but what I've tried hasn't yielded any results, so I apologize if it's been asked already.
This is also more of a math question than a programming question, but I'm doing it in JavaScript and it seemed fitting enough.
What I want to do is reduce a number more the higher it is. For example, 10 might be reduced to like 9 and 100 might be reduced to like 20. I've tried using the number itself and division, but obviously that just ret开发者_开发知识库urns a fixed number. I also have tried simple division, but all it reduced lower numbers too much and had little effect on higher numbers in comparison. Is there any formula to do this using JavaScript's Math object?
From the two examples you gave, you might be looking for a decilog scale:
function reduce(x) {
return 10 * Math.log(x) / Math.LN10 ;
}
For your examples,
reduce(100) = 20
reduce(10) = 10
A few mathematical functions that can be of some assistance are
- Square root (or any root in general)
- The log funciton (to a base that makes works for your scaling needs)
Combine these with multiplying either the result or the input by a constant and/or adding a value to the result or the input, and you'll be able to come up with a fair number of scaling choices.
You could even consider combining these functions.
A quick way to see how the function you decide on will scale numbers, would be to input them in a graphing calculator (or wolframalpha.com) and see the graph for various inputs.
Finally, a good use case for Wolfram Alpha:
http://www.wolframalpha.com/input/?i=best+fit+[10%2C+9]%2C+[100%2C+20]
精彩评论