|
Are integer numbers completely accurate? A good answer might be:Yes. 1 + 1 will always compute exactly 2, with integers. However, the size of integers is limited by the number of bits. (So, for example, with byte integers you can represent only integers in the range -128 to +127.) | |
A Loop with an Integer VariableOften a program uses an integer loop control variable which is used to compute a floating-point x for every iteration of the loop:
This is not without problems, but at least the errors in x are not accumulating: Here the problem is that the result of dividing j by 10.0 can not be represented with complete accuracy. The result of dividing an integer by a power of two, however, can be represented accurately (as long as the result is not too small.)x ln(x) 0.1 -2.3025850929940455 0.2 -1.6094379124341003 0.30000000000000004 -1.203972804325936 0.4 -0.916290731874155 0.5 -0.6931471805599453 0.6000000000000001 -0.5108256237659905 0.7000000000000001 -0.3566749439387323 0.8 -0.2231435513142097 0.9 -0.10536051565782628 1.0 0.0 1.1 0.09531017980432493 1.2000000000000002 0.1823215567939548 1.3 0.26236426446749106 1.4000000000000001 0.336472236621213 1.5 0.4054651081081644 1.6 0.47000362924573563 1.7000000000000002 0.5306282510621705 1.8 0.5877866649021191 1.9000000000000001 0.6418538861723948 2.0 0.6931471805599453 | |
QUESTION 7:Is 8 a power of two? Click Here after you have answered the question |