Sunday, April 22, 2018

Pitfall of Floating Point Representation


1. Rearrange the formula so that you can avoid subtraction of two nearly equal numbers.
for Ex:- x2 – y can be replaced by x+y.
             x – y



2.Avoid multiplication of large numbers that make left to overflow.


3.Use alternative arithmetic such as internal arithmetic if necessary.


4.Wherever possible use integer arithmetic to avoid conversion and round off errors.


5.Do-not test a floating point number for zero in your algorithm.


6.Wherever possible rearrange your formula so that you use the original data rather than derived data.


7.When finding the sum of set of members arrange the set so that they are in the ascending order of absolute value.
i.e. when | a | > | b | > | c |  , then (c - b)+a is better than (a - b)+c.

8.It necessary use double precision for floating point calculations this would include the accuracy considerably but would take more time on compute the memory space.

No comments:

Post a Comment