A good answer might be:

Because decimal-based floating point numbers have the same problem, but with different values.

Graph of Sin(x) Applet

For example 1.0/3.0 == 0.3333333.....33333 forever. All types of floating point schemes have this problem. Since binary has so many other advantages, most computers use it. (But hand calculators sometimes use decimal-based discrete calculations, since they are so much concerned with presenting results to humans.)

Say that you wanted a graph of the sine of x, for x in the range of 0.0 to 2 PI radians. Here is a start on doing this. The value of "pi" is part of the class Math, so you get it by saying Math.PI. The increment is 1 over a power of two, so it is accurate.

// assume that the drawing area is 600 by 400
public class sineWave extends Applet
{

    public void paint ( Graphics gr )
    {
        double inc = 1.0/32.0;
        for ( double x = 0.0; x <= 2*Math.PI; x = x + inc )
        {
          int startX = (int)x;
          int startY = (int)Math.sin( x );
          int endX   = (int)x + inc;
          int endY   = (int)Math.sin( x+inc );
          gr.drawLine( startX, startY, endX, endY );
        }
    }
}

The idea is that each iteration of the loop will compute two points on the curve sin(x) and connect them with a line. If the separation between all the points is small, all the straight lines will look like a curve. The various floating point values (such as x) are cast into int because that type is what drawLine() expects.

QUESTION 9:

There is a problem with the code as it is so far. Can you find it? Hint: consider the values that sin( x ) will have.

Click Here after you have answered the question