next up previous contents index
Next: Basics of Classes Up: More About C++ Previous: Functions   Contents   Index

Mathematical Functions

C++ knows several familiar mathematical functions by name:

  sqrt   exp   log   log10   ceil   floor   fabs
(fabs is the absolute value for a floating-point argument.) ePiX provides trig functions and their inverses that are sensitive to angular mode:
Cos Sin Tan
Sec Csc Cot
Acos Asin Atan
The inverse trig functions are principle branches.

The function pow(x,y) returns $ x^y$ when $ x>0$, and atan2(y,x) (N.B. argument order) returns $ \mathrm{Arg}(x+iy)\in(-\pi,\pi]$, the principle branch of arg. C++ knows many constants to 20 decimal places, such as M_PI, M_PI_2, and M_E for $ \pi$, $ \pi/2$, and $ e$ respectively. ePiX defines a few additional functions:

  recip   sgn   zero   sinx   cb   id   proj1   proj2
\begin{center}\vbox{\input{sgn.eepic}
}\end{center}         \begin{center}\vbox{\input{sinx.eepic}
}\end{center}         \begin{center}\vbox{\input{cb.eepic}
}\end{center}
recip is the reciprocal, defined to be 0 at 0; sgn is the signum function; zero is the constant function; sinx is the function $ x\mapsto \sin(x)/x$ with the discontinuity removed; cb (for ``Charlie Brown'') is the period-2 extension of the absolute value function on $ [-1,1]$; id is the identity mapping, defined for an arbitrary data type; the proj functions return their first and second variable, regardless of type.

The GNU C++ library defines other functions, including inverse hyperbolic functions (acosh, etc.), log and exp with base 2, 10, or arbitrary $ b$ (log2, etc.), the error and gamma functions (erf and tgamma [sic], respectively), and Bessel functions of first and second kind: j0, j1, y0, etc. Use, e.g., jn(5, ) to get higher indices. The GNU C library reference manual [2] describes these and other functions in detail.

Functions may be used in subsequent definitions, and functions of two (or more) variables are defined in direct analogy to functions of one variable:

double f(double t) { return t*t*log(t*t); } // t^2 \ln(t^2)
double g(double s, double t) { return exp(2*s)*Sin(t); }


next up previous contents index
Next: Basics of Classes Up: More About C++ Previous: Functions   Contents   Index
Andrew D. Hwang 2004-09-04