I've tried searching for logarithm + objective-c, but all I get is math test pages from teachers, or explanations what a logarithm is ;)
I've got some measurements that are like 83912.41234 and others are 32.94232. I need to press down this huge spectrum into something between 0 and 100, and that 32.94232 would habe to be at least something bigger than 2, where the 83912.41234 would be something near 100. So I think a logarithm function will be my friend here.
UPDATE: I've came across the math.h file through "Open Quickly" (very nice command in Xcode: SHIFT + CMD + D), and there, big surprise:
extern double log ( double );
extern float logf ( float );
extern double log10 ( double );
extern float log10f ( float );
extern double log2 ( double );
extern float log2f ( float );
extern double log1p ( double );
extern float log1pf ( float );
extern double logb ( double );
extern float logbf ( float );
But: No text, no comments. I'm not such a math-freak. So some description would be good, i.e. what kind of logarithm for what case, how the curve looks like, etc... so any great links are highly appreciated!
Also, getting a logarithm with an arbitrary base:
float logx(float value, float base)
{
return log10f(value) / log10f(base);
}
math.h is a standard include. the wikipedia page has some documentation.
Another way to 'squish' the values is to fit your values to a straight line. For you example:
Straight line equation
y = mx + c
y = 'squished' value.
x = The value you want to squish
m = Gradient of the line
c = intercept on the y axis
A quick calculation on your values gives something like:
y = 1.17e-3 x + 1.96
Hope this helps.
How about grabbing a book on C standard library functions?
Otherwise, you can try man pages:
man 3 logf
, for example
来源:https://stackoverflow.com/questions/891963/what-kind-of-logarithm-functions-methods-are-available-in-objective-c-cocoa