community.borland.com

Article #15225: Real number errors

 Technical Notes Database

TN225D.txt   Real number errors
Category   :Pascal
Platform    :All
Product    :Turbo Pascal  5.5

Description:
Q. Why don't I get the expected results when I compare & print real numbers?
A. The problem with real numbers in Turbo Pascal is a
     problem with how a real number is stored in binary form. A
     binary number has no decimal point and thus a real number
     cannot directly translate into a binary number easily.
     Calculations must be performed to break a real number down
     into it's binary representation.  As with any calculation
     that involves division or multiplication, small rounding
     errors will occur. The problem you are experiencing is a
     rounding error that occurs during translation from a real
     number into it's binary representation and back. I suggest
     that you round the results of your calculation to the number
     of decimal points that you require to alleviate the problem.


Reference:


7/16/98 4:35:30 PM
 

Last Modified: 01-SEP-99