Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "pi" and "M_PI" in objc

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.

like image 738
JFS Avatar asked Mar 05 '13 18:03

JFS


People also ask

What does M_PI mean?

M_PI. Pi, the ratio of a circle's circumference to its diameter.

What is M_PI in Arduino?

Arduino Math Constants M_PI the constant pi ( 3.14159265358979323846 )

Does Cmath have pi?

The PI constant is present in the cmath header file. The name of the constant is M_PI.


1 Answers

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

but marked as "deprecated". I assume that it is a relict from older Carbon frameworks.

M_PI is defined as a macro

#define M_PI   3.14159265358979323846264338327950288

in math.h and part of the POSIX standard.

The values are identical, but you should use M_PI for portability reasons.

(And for Swift, see How to get mathemical PI constant in Swift)

like image 169
Martin R Avatar answered Sep 22 '22 08:09

Martin R