Message-ID: <34EDA96B.1221@pobox.oleane.com> Date: Fri, 20 Feb 1998 17:03:55 +0100 From: Francois Charton Organization: CCMSA MIME-Version: 1.0 To: "Alfredo J. Cole" CC: djgpp AT delorie DOT com Subject: Re: Round off errors References: <01bd3e0c$200881c0$LocalHost AT alfredoc> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Alfredo J. Cole wrote: > > Compiling the following code with DJGPP gives the erroneous result > (5551.20). The same code compiled with Borland's bcd class gives the > correct result (5551.22). I am developing an accounting system with > DJGPP and it requires that the results be exact. Is there a similar > class or option under DJGPP that will eliminate these round off > errors? > Round off errors are a property of floating point representation. You can never eliminate them totally. However, if all the data you use have the same number of decimal places (usually the case with monetary terms), you can avoid round off problems by using integers only. In your example, multiply all the figures by 100, and do all the math in integers. With standard integers (ie longs in djgpp), you will be able to represent numbers up to tens of millions, if it is not sufficient, you may uses "long long" which provide for even longer integers. Francois