python:
import math
print("ln(100)", math.log(100), sep=" = ")
print("log2(256)", math.log(256, 2), sep=" = ", end="\n\n")
print("sin(30°)", math.sin(math.radians(30)), sep=" = ")
print("cos(60°)", math.cos(math.radians(60)), sep=" = ")
print("tan(45°)", math.tan(math.radians(45)), sep=" = ", end="\n\n")
print("asin(0.5)", math.degrees(math.asin(0.5)), sep=" = ")
print("acos(0.5)", math.degrees(math.acos(0.5)), sep=" = ")
print("atan(1)", math.degrees(math.atan(1)), sep=" = ")
运行结果:
C++:
#include <iostream>
#include <cmath>
const double PI = acos(-1);
using namespace std;
int main() {
cout << "ln(100) = " << log(100.0) << endl;
cout << "log2(256) = " << log(256.0) / log(2.0) << endl << endl;
cout << "sin(30°) = " << sin(30.0 * PI / 180.0) << endl;
cout << "cos(60°) = " << cos(60.0 * PI / 180.0) << endl;
cout << "tan(45°) = " << tan(45.0 * PI / 180.0) << endl << endl;
cout << "asin(0.5) = " << asin(0.5) / PI * 180.0 << endl;
cout << "acos(0.5) = " << acos(0.5) / PI * 180.0 << endl;
cout << "atan(1) = " << atan(1) / PI * 180.0 << endl;
return 0;
}
运行结果:
可以看到,python对于 sin(30°) cos(60°) asin(0.5) acos(0.5) 的求值并不准确。