Xco*_*der 32 iphone objective-c
当我尝试使用pi时,我的iPhone编程一直出错.我尝试着
float pNumber = 100*cos(2 * pi * (days/23));
Run Code Online (Sandbox Code Playgroud)
但我得到的错误说:
_pi,引用自
_pi $ non_lazy_ptr
我在互联网上的某个地方看到使用M_PI并编译,但我不认为它给了我正确的计算.
当我尝试:
float pNumber = 100*cos(2 * M_PI * (15746/23));
Run Code Online (Sandbox Code Playgroud)
我得到0
谢谢
Jon*_*ler 55
M_PI并查看它的内容(printf("M_PI = %16.9g\n", M_PI);在C中).cos()吗?如果不是,它可以被解释为返回整数(#include <math.h>可能)的函数.示例代码(在带有GCC 4.3.3的Solaris 10 SPARC上的C中测试):
#include <math.h>
#include <stdio.h>
int main(void)
{
float pNumber = 100*cos(2 * M_PI * (15746/23));
printf("M_PI = %16.9g\n", M_PI);
printf("pNum = %16.9g\n", pNumber);
pNumber = 100*cos(2 * M_PI * (15746/23.0));
printf("pNum = %16.9g\n", pNumber);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
示例输出:
M_PI = 3.14159265
pNum = 100
pNum = -77.5711288
Run Code Online (Sandbox Code Playgroud)