"pi"和"pi"有什么区别?和"M_PI"在objc中 [英] What's the difference between "pi" and "M_PI" in objc
问题描述
在我的代码中包括一些数学运算时,我偶然发现了常量"PI".
至少在我的Xcode 4.6版中,我可以使用任何一个.但是pi
和M_PI
有什么区别?有关该主题的文档很少.
Including some math in my code I stumbled over the constant "PI".
At least in my Xcode version 4.6 I could use either one. But what is the difference between pi
and M_PI
? The documentation is little bit tight on that topic.
推荐答案
pi
在"CarbonCore.framework"标头中定义为
pi
is defined in the "CarbonCore.framework" headers as
extern const double_t pi __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_8, __IPHONE_NA, __IPHONE_NA);
,但标记为已弃用".我认为这是旧版Carbon框架的遗物.
but marked as "deprecated". I assume that it is a relict from older Carbon frameworks.
M_PI
被定义为宏
#define M_PI 3.14159265358979323846264338327950288
在 math.h
中
以及POSIX标准的一部分.
in math.h
and part of the POSIX standard.
这些值是相同的,但是出于可移植性的原因,您应该使用M_PI
.
The values are identical, but you should use M_PI
for portability reasons.
(对于 Swift ,请参见如何在Swift中获取数学PI常量.)
这篇关于"pi"和"pi"有什么区别?和"M_PI"在objc中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!