Effective Programming Practices
Reading: Cheney & Kincaid, (pp. 721-729 );
- Numerical Math != Math. Common sense tricks in evaluating
mathematical expressions. On the right hand side is an equivalent better
suited for numerical calculations.
MATH =====> NUMERICAL MATH
x^2 =====> x*x
x^7 =====> x*x*x*x*x*x*x (!) Never pow(x, 7)
x/2 =====> 0.5*x
Sum(3*x_i) =====> for(i=0; i<100; i++) s+= x[i]; s = s*3.0; // do
the sum first, then multiply by a constant //
ln(1 + x) ======> x - 0.5*x*x (if x is very small, so x^3 < your
precision).