A good answer might be:
| |
Floating-point Loop ControlFor counting loops (and many other loops) it is best to use an integer type for the loop control variable. However, a loop control variable can be a floating point type, with a fractional increment. The following program prints a table that gives "x" and "ln( x )" for values of x from 0.1 up to about 2.0:
It compiles correctly, and runs. But its output is not pretty: Remember (from a previous chapter) that floating point numbers are not absolutely accurate. In particular, 0.1 is always slightly wrong when represented inside a computer, no matter how many bits are used. The errors in x accumulate, and x drifts away from the desired value.x ln(x) 0.1 -2.3025850929940455 0.2 -1.6094379124341003 0.30000000000000004 -1.203972804325936 0.4 -0.916290731874155 0.5 -0.6931471805599453 0.6 -0.5108256237659907 0.7 -0.35667494393873245 0.7999999999999999 -0.22314355131420985 0.8999999999999999 -0.1053605156578264 0.9999999999999999 -1.1102230246251565E-16 1.0999999999999999 0.09531017980432474 1.2 0.1823215567939546 1.3 0.26236426446749106 1.4000000000000001 0.336472236621213 1.5000000000000002 0.40546510810816455 1.6000000000000003 0.47000362924573574 1.7000000000000004 0.5306282510621706 1.8000000000000005 0.5877866649021193 1.9000000000000006 0.641853886172395 | |
QUESTION 6:Are integer numbers completely accurate? Click Here after you have answered the question |