next up previous
Next: Example Up: Overview of C++ Previous: Activity

Math Functions

Several kinds of functions are available in C++. For the time being we will use a group of predefined functions. These are programs that are supplied with most C++ compilers. The header file that must be included for math functions is
\begin{emph}
math.h \end{emph}
. The predefined functions when used in a C++ statement, the argument is enclosed in parentheses following the name of the function. Table 2.4 below shows some of the math functions that you can use. Confusion could result if a variable were defined with the same name as that of a predefined function. Therefore, good practice dictates that names of variables should not be chosen to be the same as the predefined functions.
 

 
Table 2.4: Some predefined functions in C++
Name Meaning
abs( ) Absolute value
sqrt( ) Square root
log( ) Logarithm to the base e=2.71828
log10 ( ) Logarithm to the base 10
exp( ) Power of e or exponential
sin( ) Sine of the angle whose measure is given in radians
cos( ) Cosine the angle whose measure is given in radians
tan( ) Tangent of the angle whose measure is given in radians
atan( ) Arctagnget or principal angle in radians of a given value
acos( ) Arccosine
asin( ) Arcsine
ceil( ) Rounds numbers up to nearest integer
floor( ) Rounds numbers down to the nearest integer
pow(x,y) xy




 
next up previous
Next: Example Up: Overview of C++ Previous: Activity
Yousef Haik
2/23/1998