views:

379

answers:

4

Is there a method for determining the base 10 log of any number in the iPhone language? Any help with the math for this would be appreciated by a newbie budding iPhone developer. Thanks in advance. M

+1  A: 

logA(x) = ln(x)/ln(A)

gonzo
A: 
log_n x / log_n 10

where log_n is log to any base

nlucaroni
+4  A: 

Objective-C is an extension of C--you can use the C log10 function from math.h:

#include <math.h>
@implementation MathUtils
+ (CGFloat)log10:(CGFloat)value
{
    return log10(value);
}
@end;
rpetrich
A: 

Why bother wrapping it in an ObjC method? As you say, Objective-C is an extension of C:

#include <math.h>

float doSomeComputation(float x)
{
    // ...
    float y = log10f(x); // drop the 'f' if you're using doubles
    // ...
    return y;
}

Perfectly valid Objective-C.

Stephen Canon