【发布时间】:2011-04-16 14:42:20
【问题描述】:
我想在 iOS 中计算对数。 Objective-C 可以做到这一点吗?
【问题讨论】:
标签: iphone objective-c logarithm
我想在 iOS 中计算对数。 Objective-C 可以做到这一点吗?
【问题讨论】:
标签: iphone objective-c logarithm
您可以使用C functions 来计算对数
#import <math.h>
double myLog = log(10);
您也可以在这里查看:What kind of logarithm functions / methods are available in objective-c / cocoa-touch?
【讨论】:
我们可以使用 C 中可用的相同数学函数在 Objective-C 中进行数学运算。
我使用以下函数进行数学运算。这里这些函数的返回类型是双精度,参数也应该是双精度类型......所以
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)];
【讨论】:
是的。
Objective C 是 ANSI C 的超集,iOS 支持使用大多数常用的 C 库。
因此,您可以使用 C 库 math.h,其中包含多个日志函数(base10、base e、float result、double result 等)
【讨论】: