From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: Round off errors Date: Fri, 20 Feb 1998 10:50:40 -0600 Organization: Cornell University Lines: 41 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <34EDB460.1AC6@cornell.edu> References: <01bd3e0c$200881c0$LocalHost AT alfredoc> Reply-To: sinan DOT unur AT cornell DOT edu NNTP-Posting-Host: 128 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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 fact of life if you are using floating point arithmetic. your best bet is not to use floating point arithmetic for accounting software. note that this is _not_ at all a djgpp specific problem. basic floating point. if you want to see another example, try C:\TEMP>type fp.c #include int main(void) { int i; float g, data[3] = { 1, -10e9, 10e9}; for(g=0.0, i=0; i<3; i++) g += data[i]; printf("%g\n",g); for(g=0.0, i=0; i<3; i++) g += data[2-i]; printf("%g\n",g); return 0; } C:\TEMP>fp 0 1 -- Sinan