math.h中的常量

类似于Matlab中经常用到的一些常量,C++里边也是有的。(经查源文件无意中看到)
写入如下代码:
 1 #include<iostream>
 2 #include<iomanip>
 3 #define _USE_MATH_DEFINES
 4 #include<math.h>
 5 using namespace std;
 6 int main()
 7 {
 8 system("color 3e");
 9 int a=255;
10 cout<<setprecision(20);
11 cout<<"e          "<<M_E<<endl;
12 cout<<"log2(e)    "<<M_LOG2E<<endl;
13 cout<<"log10(e)   "<<M_LOG10E<<endl;
14 cout<<"ln(2)      "<<M_LN2<<endl;
15 cout<<"ln(10)     "<<M_LN10<<endl;
16 cout<<"pi         "<<M_PI<<endl;
17 cout<<"1/pi       "<<M_1_PI<<endl;
18 cout<<"2/pi       "<<M_2_PI<<endl;
19 cout<<"pi/2       "<<M_PI_2<<endl;
20 cout<<"pi/4       "<<M_PI_4<<endl;
21 cout<<"sqrt(2)    "<<M_SQRT2<<endl;
22 cout<<"1/sqrt(2)  "<<M_SQRT1_2<<endl;
23 cout<<"2/sqrt(pi) "<<M_2_SQRTPI<<endl;
24 cout<<"八进制:   "<<oct<<a<<endl;
25 cout<<"十进制:   "<<dec<<a<<endl;
26 cout<<"十六进制: "<<hex<<a<<endl;
27 cout<<"八进制:   "<<setbase(8)<<a<<endl;
28 cout<<"十进制:   "<<setbase(10)<<a<<endl;
29 cout<<"十六进制: "<<setbase(16)<<a<<endl;
30 return 0;
31 }

 


 

posted @ 2013-09-02 12:35  Tosone  阅读(604)  评论(0)    收藏  举报