On some (especially older) platforms (see the comments below) you might need to
(在某些(特别是较旧的)平台上(请参阅下面的评论),您可能需要这样做)
#define _USE_MATH_DEFINES
and then include the necessary header file:
(然后包含必要的头文件:)
#include <math.h>
and the value of pi can be accessed via:
(pi的值可以通过以下方式访问:)
M_PI
In my math.h
(2014) it is defined as:
(在我的math.h
(2014)中,它被定义为:)
# define M_PI 3.14159265358979323846 /* pi */
but check your math.h
for more.
(但请查看math.h
了解更多信息。)
An extract from the "old" math.h
(in 2009): (来自“旧” math.h
的摘录(2009年):)
/* Define _USE_MATH_DEFINES before including math.h to expose these macro
* definitions for common math constants. These are placed under an #ifdef
* since these commonly-defined names are not part of the C/C++ standards.
*/
However:
(然而:)
on newer platforms (at least on my 64 bit Ubuntu 14.04) I do not need to define the _USE_MATH_DEFINES
(在较新的平台上(至少在我的64位Ubuntu 14.04上)我不需要定义_USE_MATH_DEFINES
)
On (recent) Linux platforms there are long double
values too provided as a GNU Extension:
(在(最近的)Linux平台上,作为GNU扩展提供了long double
值:)
# define M_PIl 3.141592653589793238462643383279502884L /* pi */
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…