Article View: comp.lang.pascal.borland
Article #403Re: Help, Help, Help BCD
From: Robert AH Prins
Date: Fri, 18 Dec 1998 00:00
Date: Fri, 18 Dec 1998 00:00
56 lines
3346 bytes
3346 bytes
In article <367A4B0E.CA324425@gisma.de>, r.rochow@gisma.de wrote: > Hi Robert, > > thinks about a medium list ( a customer having his acount for 5 years with 20 > movements each month has about 1200 movments ) of cash-acounts, which are to > be calculated for a saldo. So in most currencys the fractional part has 2 > digits and range from x,00 to x,99. So 0,25 or 0,50 are ( negative ) powers of > 2 they can be represented in biniary values ( double, extendet ) exactly. > Values like x,49 or x,96 can't be represendet in double-datatypes -> they > would result in something like x,489982938739 of x,960021232313. Add two of > this values and then rounding the result should bring up the correct value. > But adding hundreds or thousands of this values and then rounding the result > is a mistake. Unfortunately I am all to aware of this, at Willis we have to apportion premiums over many (dozens of) underwriters, and it's a nightmare. All of out batch programs actually abend if there are control differences, even if only 1 pence! As some posters wrote, use COMP (-2^63 .. 2^63-1), or consider splitting up your amounts into separate totals for the integer & fractional parts. It would extend your range to 2,147,483,647.99 (longint) or 9,223,372,036,854,775,807.99 (comp), which might be enough, and which would certainly be faster than using BCD. > The workaround is to round the value each time an operation is done. Very time consuming, especially if you're using the FPU as every rounding will save/change/restore the controlword when you're using pure Pascal. > In my newer c++ programs I use a BCD-Libray ( Money++ from roguewave ) > and I have no problems with rounding error. > > So this is the first reason I'm looking for a BCD-Unit for pascal. Never considered writing some small C++ programs and looking at the generated code in this BCD library with debug or IDA? > The second reason is that I get this values from a ISAM-Database and put the > results to a database ( i use Btrieve 6.15 ). This database is able to deal > with BCD-Values directly. > > Do you have a good BCD-lib/unit or information where get a good BCD-lib/unit > please let me know. There are a few long-number units available on the pages of some of the regular posters in comp.lang.pascal.borland. Robert -- Robert AH Prins prinsra@williscorroon.com -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Technical Details
Message-ID:
<75dvja$4cd$1@nnrp1.dejanews.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<36782716.D160ADCD@gisma.de> <75aumk$hj6$1@nnrp1.dejanews.com> <367A4B0E.CA324425@gisma.de>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111659,743ddf2b86ac5133 X-Google-Attributes: gid111659,public X-Google-Thread: 108ebd,497dcada11896622,start X-Google-Attributes: gid108ebd,public From: Robert AH Prins <prinsra@williscorroon.com> Subject: Re: Help, Help, Help BCD Date: 1998/12/18 Message-ID: <75dvja$4cd$1@nnrp1.dejanews.com> X-Deja-AN: 423628851 References: <36782716.D160ADCD@gisma.de> <75aumk$hj6$1@nnrp1.dejanews.com> <367A4B0E.CA324425@gisma.de> X-Http-Proxy: 1.0 x5.dejanews.com:80 (Squid/1.1.22) for client 193.130.234.1 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Fri Dec 18 16:24:15 1998 GMT Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal X-Http-User-Agent: Mozilla/3.0 (Win16; I)