next up previous
Next: Assessment of scale_change Program Up: Operator Precedence Previous: Operator Precedence

Intermediate Results

Since the computer will execute only one operation at a time, the order of precedence determines the order in which the operations are performed. Intermediate results are computed in the appropriate order. Let us consider the formula for the roots of the quadratic equation.

\begin{displaymath}x1 = \frac{-b + \sqrt{b^2 - 4 ac}}{2a} \end{displaymath}

is written in C++ as:
       float a, b, c;
       float x1;
       ...
       x1 = ( -b + sqrt(b*b -4*a*c))/(2*a);
and actually computed as:
       float  a, b, c;
       float  x1;
       float  temp, temp2;
       ...
       temp = b*b;
       temp2= a*c;
       temp2= 4*temp2;
       temp = temp - temp2;
       temp = sqrt(temp);
       temp = -b + temp;
       temp2= 2*a;
       x1   = temp/temp2;
Where temp, temp2 are intermediate results.



J. C. Diaz 2004-01-19