This page lists the Math Functions that can be used in C++.
Function |
Description |
Example |
abs(x) |
Returns the absolute vlaue of x. |
abs(-5) returns 5 |
ceil(x) |
Rounds x up to the nearest integer. |
ceil(3.2) returns 4 ceil(-3.2) returns 3 |
floor(x) |
Rounds x down to the nearest integer. |
floor(3.2) returns 3 floor(-3.2) returns -4 |
exp(x) |
Returns the exponetial function of x. Thus is the same as e^x. |
exp(1) returns 2.71828 |
pow(x,y) |
Returns x to the y power. |
pow(3,4) returns 81 |
log(x) |
Returns the natuaral lograithm of x. |
log(2.71828) returns 1.0 |
log10(x) |
Returns the base-10 logarithm of x. |
log10(10.0) returns 1 |
sqrt(x) |
Returns the square root of x. |
sqrt(25) returns 5 |
sin(x) |
Returns the sine of x, x being the angle in radians. |
sin(3.14459) returns 0 |
cos(x) |
Returns cosine of x, x being the angle in radians. |
cos(3.14159) returns -1 |
tan(x) |
Returns tangent of x, x being the angle in radians. |
tan(3.14159 / 4) returns 1 |
fmod(x,y) |
Returns remainder of x/y as a double. |
fmod(2.4, 1.3)) returns 1.1 |
rand() |
Returns an random number. |
No Example |
srand(seed) |
Sets a new seed for the random number generator. |
srand(500) |
max(a,b) |
Returns the maximum number, weather its a or b. |
max(3,7) |
min(a,b) |
Returns the minimum number, weather its a or b. |
min(7,1) |