问题
I want to calculate a logarithm in iOS. Can Objective-C do this?
回答1:
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?
回答2:
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)];
回答3:
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.)
来源:https://stackoverflow.com/questions/3784418/how-do-i-calculate-a-logarithm-in-ios