What kind of logarithm functions / methods are available in objective-c / cocoa-touch?

Thanks picture Thanks · May 21, 2009 · Viewed 12.7k times · Source

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!

Answer

Adam Wiggins picture Adam Wiggins · Oct 20, 2009

Also, getting a logarithm with an arbitrary base:

float logx(float value, float base) 
{
   return log10f(value) / log10f(base);
}