5

I want to calculate a logarithm in iOS. Can Objective-C do this?

0

3 Answers 3

10

You can use the C functions for calculating logarithms

#import <math.h>
double myLog = log(10);

You can also see here: What kind of logarithm functions / methods are available in objective-c / cocoa-touch?

1

We can use the same math functions which are available in C to do math operations in Objective-C.

I have used the following functions to do mathematical operations. Here the return type of these functions is double and argument should also be of double type... so

double number;

display.text = [NSString stringWithFormat:@"%f" ,log(number)];  
display.text = [NSString stringWithFormat:@"%f" ,log2(number)]; 

display.text = [NSString stringWithFormat:@"%f" ,log10(number)];
display.text = [NSString stringWithFormat:@"%f" ,exp(number)];
0

Yes.

Objective C is a superset of ANSI C, and iOS supports using most of the usual C libraries.

Thus, you can use the C library math.h, which include several log functions (base10, base e, float result, double result, etc.)

Not the answer you're looking for? Browse other questions tagged or ask your own question.