I keep getting error in my iPhone programing when I try to use pi. I'm trying
float pNumber = 100*cos(2 * pi * (days/23));
But i get errors that say:
_pi, referenced from
_pi$non_lazy_ptr
I saw somewhere on the internet to use M_PI and it compiles but I don't think it gives me the correct calculation.
When I try:
float pNumber = 100*cos(2 * M_PI * (15746/23));
I get 0
Thanks
M_PI. Pi, the ratio of a circle's circumference to its diameter. M_PI_2. Pi divided by two.
The PI constant is present in the cmath header file. The name of the constant is M_PI.
alt + p is the shortcut (on US-keyboards) that will create the π unicode character.
M_PI
and see what it says (printf("M_PI = %16.9g\n", M_PI);
in C).cos()
? If not, it may be interpreted as a function returning an integer (#include <math.h>
perhaps).Example code (tested in C on Solaris 10 SPARC with GCC 4.3.3):
#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; }
Example output:
M_PI = 3.14159265 pNum = 100 pNum = -77.5711288
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With