如何在 iOS 中计算对数?

发布于 2024-09-25 01:47:36 字数 43 浏览 8 评论 0原文

我想在 iOS 中计算对数。 Objective-C 可以做到这一点吗?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

趴在窗边数星星i 2024-10-02 01:47:36

您可以使用 C 函数 计算对数

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

您还可以请参阅此处:什么样的对数函数/方法在 Objective-C / Cocoa-touch 中可用吗?

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?

扛起拖把扫天下 2024-10-02 01:47:36

我们可以使用 C 中可用的相同数学函数在 Objective-C 中进行数学运算。

我使用以下函数进行数学运算。这里这些函数的返回类型是 double 并且参数也应该是 double 类型......所以

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)];

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)];
陈甜 2024-10-02 01:47:36

是的。

Objective C 是 ANSI C 的超集,iOS 支持使用大多数常用的 C 库。

因此,您可以使用 C 库 math.h,其中包括多个对数函数(base10、base e、float result、double result 等)

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文