next up previous contents
Next: Control Flow Up: Simple Input / Output Previous: Cost of Arithmetic Operators

 

Precision Errors

Each time two real numbers are combined there is a slight loss of accuracy in the result. After many such operations such 'round-off' errors become noticeable. Catastrophic accuracy loss often arises because two values that are almost equal are subtracted, the subtraction may cancel the leading digits and promotes errors very rapidly from low order digits to high order ones.

For example, consider, the numbers .123456 and .123446; these may be approximated in memory as .123457 and .123445 respectively, whereas the true difference is .100000D-4 the representation may give .130000D-4, a 30% error.

    x = 0.123456; y = 0.123446
    PRINT*, "x = ",x," y = ",y
    PRINT*, "x-y = ",x-y," but should be 0.100d-4"

May produce:

    x = 0.123457  y = 0.123445
    x-y = 0.130d-4 but should be 0.100d-4

A whole branch of Numerical Analysis is dedicated to minimising this class of errors in algorithms.

Return to corresponding overview page gif


next up previous contents
Next: Control Flow Up: Simple Input / Output Previous: Cost of Arithmetic Operators

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.