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
+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
2009-08-14 23:43:43
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
2009-08-15 22:54:09