C++Builder - X to the power y, and other math functions
To get the power of a number in C++, use the function pow(base, exponent).
You can use the function like this:
double p;
p = pow(3, 2); // 9
p = pow(2, 3); // 8
p = pow(4, 0.5); // 4 to the power 0.5 gives 2
Some math functions:
Function |
Meaning |
Example |
abs(x) |
absolute value |
abs(-10) returns 10 |
atan(x) |
arctangent |
atan(0.4) returns 21.8 |
cos(x) |
cosine |
cos(45) returns 0.5253... |
DegToRad(x) |
degrees to radians |
DegToRad(45) returns 0.78539... |
10Log10(x) |
logarithm, base 10 |
Log10(100) returns 2 |
Log2(x) |
logarithm, base 2 |
Log2(8) returns 3 |
LogN(base, x) |
logarithm, any base |
LogN(2, 8) returns 3 |
pow(base, exponent) |
power |
pow(3,2) returns 9 |
RadToDeg(x) |
radians to degrees |
RadToDeg(0.78540) returns 45.0001... |
sin(x) |
sine |
sin(45) returns 0.707106... |
sqrt(x) |
square root |
sqrt(16) returns 4 |
tan(x) |
tangent |
tan(45) returns 1 |
|
|