Math 常量Math Constants

语法Syntax

#define _USE_MATH_DEFINES // for C++  
#include <cmath>  

#define _USE_MATH_DEFINES // for C  
#include <math.h>  

备注Remarks

下列符号定义了其所指示的表达式的值:The following symbols are defined for the values of their indicated expressions:

符号Symbol ExpressionExpression Value
M_EM_E ee 2.718281828459045235362.71828182845904523536
M_LOG2EM_LOG2E log2(e)log2(e) 1.442695040888963407361.44269504088896340736
M_LOG10EM_LOG10E log10(e)log10(e) 0.4342944819032518276510.434294481903251827651
M_LN2M_LN2 ln(2)ln(2) 0.6931471805599453094170.693147180559945309417
M_LN10M_LN10 ln(10)ln(10) 2.302585092994045684022.30258509299404568402
M_PIM_PI pipi 3.141592653589793238463.14159265358979323846
M_PI_2M_PI_2 pi/2pi/2 1.570796326794896619231.57079632679489661923
M_PI_4M_PI_4 pi/4pi/4 0.7853981633974483096160.785398163397448309616
M_1_PIM_1_PI 1/pi1/pi 0.3183098861837906715380.318309886183790671538
M_2_PIM_2_PI 2/pi2/pi 0.6366197723675813430760.636619772367581343076
M_2_SQRTPIM_2_SQRTPI 2/sqrt(pi)2/sqrt(pi) 1.128379167095512573901.12837916709551257390
M_SQRT2M_SQRT2 sqrt(2)sqrt(2) 1.414213562373095048801.41421356237309504880
M_SQRT1_2M_SQRT1_2 1/sqrt(2)1/sqrt(2) 0.7071067811865475244010.707106781186547524401

数学常量未在标准 C/C++ 中进行定义。Math Constants are not defined in Standard C/C++. 若要使用它们,必须首先定义 _USE_MATH_DEFINES,然后将 cmath 或 math.h 包含在内。To use them, you must first define _USE_MATH_DEFINES and then include cmath or math.h.

在“发布模式”下生成项目时,文件 ATLComTime.h 包含 math.h。The file ATLComTime.h includes math.h when your project is built in Release mode. 如果在同时包含 ATLComTime.h 的项目中使用了一个或多个数学常量,则在包含 ATLComTime.h 前必须先定义 _USE_MATH_DEFINESIf you use one or more of the math constants in a project that also includes ATLComTime.h, you must define _USE_MATH_DEFINES before you include ATLComTime.h.

另请参阅See Also

全局常量Global Constants