go to previous page   go to home page   go to next page hear noise highlighting

Answer:

Yes.


Calculate Each Float

Use the for-loop structure to correctly and safely count. Calculate a new value of the floating point variable each time.

double x;
int    j;

for ( j = 0; j < 100; j++ )
{
  x = j/10.0;
  
  // do something with x
}

Almost always, floating point work should be done with double precision, as above.

An even more accurate version of the loop is:

double x;
int    j;

for ( j = 0; j < 160; j++ )
{
  x = j/16.0;
  
  // do something with x
}

This is better because (1/16) is accurately represented in binary.


QUESTION 19:

Is floating point representation (as used in computers) the same as the base two notation discussed in this chapter?


go to previous page   go to home page   go to next page