Sender: tim AT ipi DOT ac DOT ru Message-ID: <34F15244.613633AF@ipi.ac.ru> Date: Mon, 23 Feb 1998 13:41:08 +0300 From: "Timofei V. Bondarenko" 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. Yes, it is because type 'float' contains only 20bit mantisse. Somewhere in (or ) you can see declaration FLT_DIG - the precesion of float in decimal digits For ieee compliant 32 bits float it will be only 6, so your is quite predictible. > Is there a similar > class or option under DJGPP that will eliminate these round off > errors? Use 'double': it will be faster and increase precesion up to 15 decimal digits (DBL_DIG). OR try to use fixed-point arythmetic - it will works like this: int val = 555122; printf("val = %d.%02d\n", val / 100, val % 100); regards tim.