Re: round off problem
- Posted by George Walters <gwalters at sc.rr.com> Jun 28, 2004
- 454 views
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> </head> <body bgcolor="#ffffff" text="#000000"> Mike, If EU stores atoms with double precision (i.e 15 places per the manual) then any round off would be negligible over a fairly large number of additions. The only problem comes on comparisons which I would have to do something like this<br> <br> If abs(number1 - number2) > .001 <br> <br> for an equality test. If the difference is less than a penny then the figures are equal , at least financially.<br> <br> george<br> <br> <br> Mike Nelson wrote:<br> <blockquote cite="mid928259027-1463792382-1088438917 at boing.topica.com" type="cite"> </pre> <blockquote type="cite"> <pre wrap="">I have imported general ledger data from a working system in another OS into mysql using Matt's ODBC tools. Trying to finish the EU general ledger software, I've run into serious round off issues. Here's a couple of examples to show the problem. A typical account balance: Mysql shows -1143.46 which is correct EU trace shows -1143.459961 which is not accurate to 15 places as the EU manual states. Totalling the credits and debits over the entire file of transactions gives the following (printing with a mask of %12.2f.) Debits = 4642782.63 Credits= 4642782.56 Off by 4 cents. The input data from the other OS is balanced. It looks like there's about 8 places of accuracy not 15. The data records are always read into a sequence, then arithmetic is done with atoms. </pre> </blockquote> <pre wrap=""><!----> Euphoria atoms are IEEE double precision floating points. They should never be used for fiannical calculations, as many common decimal values cannot be accuratrly represented in this type of value. For example, .01 has no finite binary rerpesentation and therefor can't be exactly represented in an atom. No doubt your source uses Binary Coded Decimal internally, which can represent .01 exactly. (By the way BCD calculations are horribly slow vs binary floating point and for this reason are never used except in finacial calcualtions.) Euphoria can't handle BCD directly but there are workarounds. If your totals are constitently under 10,000,000 you can express all values in cents and store them as Eu integers. If you are dealing with larger values, you will need a libray for big numbers--check the contributions page. -- Mike Nelson </pre> </blockquote> </body> </html>