C++ 中的数学计算函数
这是我从网上搜集来的,值得看看。
1 #include <iostream> 2 #include <cmath> 3 using namespace std; 4 int main() 5 { 6 double pi,e,n; 7 int i; 8 pi = acos(-1.0); 9 e = exp(1.0); 10 cout << "abs(-10) = " << abs(-10) << "\n";//求整数的绝对值 11 cout << "fabs(-10.8) = " << fabs(-10.8) << "\n"; 12 cout << "asin(0.5) = " << asin(0.5) << " (π/6)\n"; 13 cout << "atan(1.0) = " << atan(1.0) << " (π/4)\n"; 14 cout << "atan2(1.0,√3) = " << atan2(1.0,sqrt(3.0)) << " (π/6)\n"; 15 cout << "sin(π/2) = " << sin(pi / 2.0) << "\n"; 16 cout << "sinh(π/2) = " << sinh(pi /2.0 ) << "\n"; 17 cout << "cos(π/2) = " << cos(pi / 2.0) << " (≈0.0)\n"; 18 cout << "cosh(π/2) = " << cosh(pi /2.0 ) << "\n"; 19 cout << "tan(π/4) = " << tan(pi / 4) << "\n"; 20 cout << "tanh(π/4) = " << tanh(pi /4 ) << "\n"; 21 cout << "ceil(1.3) = " << ceil(1.3) << "\n"; 22 cout << "ceil(-1.3) = " << ceil(-1.3) << "\n"; 23 cout << "floor(1.3) = " << floor(1.3) << "\n"; 24 cout << "floor(-1.3) = " << floor(-1.3) << "\n"; 25 cout << "log(e*e) = " << log(e*e) << "\n"; 26 cout << "log10(1000.0) = " << log10(1000.0) << "\n"; 27 cout << "fmod(10.2,3.0) = " << fmod(10.2,3.0) << "\n"; 28 cout << "fmod(-10.2,3.0) = " << fmod(-10.2,3.0) << "\n"; 29 cout << "pow(25.0,2.0) = " << pow(25.0,2.0) << "\n"; 30 cout << "modf(-12.3435,&n) = " << modf(-12.3435,&n) << ","; 31 cout << "n = " << n << "\t-12.3435 = n + modf(-12.3435,&n)\n"; 32 cout << "frexp(17.0,&i) = " << frexp(17.0,&i) << ","; 33 cout << "i = " << i << "\t17.0 = frexp(17.0,&i)*2^i\n"; 34 cout << "ldexp(0.53125,5) = " << ldexp(0.53135,5) << "\tldexp(0.53125,5)=0.53125*2^5\n"; 35 return 0; 36 } 37 /* 38 输出结果: 39 abs(-10) = 10 40 fabs(-10.8) = 10.8 41 asin(0.5) = 0.523599 (π/6) 42 atan(1.0) = 0.785398 (π/4) 43 atan2(1.0,√3) = 0.523599 (π/6) 44 sin(π/2) = 1 45 sinh(π/2) = 2.3013 46 cos(π/2) = 6.12303e-017 (≈0.0) 47 cosh(π/2) = 2.50918 48 tan(π/4) = 1 49 tanh(π/4) = 0.655794 50 ceil(1.3) = 2 51 ceil(-1.3) = -1 52 floor(1.3) = 1 53 floor(-1.3) = -2 54 log(e*e) = 2 55 log10(1000.0) = 3 56 fmod(10.2,3.0) = 1.2 57 fmod(-10.2,3.0) = -1.2 58 pow(25.0,2.0) = 625 59 modf(-12.3435,&n) = -0.3435,n = -12 -12.3435 = n + modf(-12.3435,&n) 60 frexp(17.0,&i) = 0.53125,i = 5 17.0 = frexp(17.0,&i)*2^i 61 ldexp(0.53125,5) = 17.0032 ldexp(0.53125,5)=0.53125*2^5 62 */ 63 /* 64 abs; acos; asin; atan; atan2; ceil;cos; cosh; exp; 65 fabs; floor; fmod; frexp; ldexp; log;log10; modf; pow; 66 sin; sinh; sqrt;tan; tanh; 67 acosf; asinf; atanf; atan2f; ceilf; cosf; coshf; expf; 68 fabsf; floorf; fmodf; frexpf; ldexpf; logf; 69 log10f; modff; powf; sinf; sinhf; sqrtf; tanf; tanhf; 70 acosl; asinl; atanl; atan2l; ceill; cosl; coshl; expl; 71 fabsl; floorl; fmodl; frexpl; ldexpl; logl; 72 log10l; modfl; powl; sinl; sinhl; sqrtl; tanl; tanhl; 73 */(王朝网络 wangchao.net.cn)