How do I calculate a logarithm in iOS? [duplicate]

戏子无情 提交于 2019-12-01 17:29:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!