If the mantissa has at least seven or eight bits below the binary point,
equivalence to the cents level is achieved by |x-y| < 0.005; the half-cent
is x'0.0147ae' which can be done in any decent language. If you do it as a
procedure, you can do magnitude checks to ensure that the magnitude of the
currency quantity doesn't bump the exponent too high, possibly with a check
on magnitude of the binary exponent.
Another aspect to consider is that rounding binary values to cents will do
exactly the same thing. Every time a financial program produces output for
any people to read this is done as part of the formatting for I/O.
But I think that's almost all moot. The only times we will need to go to
the library are for transcendental functions (trigonometric, log,
exponential, and other scientific and mathematical functions).
Exponentiation to integers is usually done by computing an array of squared
quantities and using the bit pattern of the exponent to roll them up into
the result. For real-world financial computation where binary floating
point is an issue, we are pretty much limited to exponentiations used in
interest calculations, which are probably best done in binary floating point
and rounded to the nearest cent. Look rationally at alternatives to doing
this in decimal and binary arithmetic and you will be dealing with the
reasons that all modern computers are binary, in their cores.
On the other hand, if you want to do a mathematical library in base-ten
arithmetic, all you need to worry about is executing them vast quantities of
times because practical problems will require this type of computation a
limited number of times, so speed isn't a problem, and, in the age of
terabyte HDs, space isn't either. This may be what someone wants, but you
will never make a decisive case for such a library in the context of
numerical analysis and computer science.
James K Beard
From: Jim Michaels [mailto:[email protected]]
Sent: Friday, March 25, 2011 4:16 PM
To: [email protected]
Subject: Re: [Mingw-w64-public] mingw-w64 Decimal Floating Point math
I can add this:
If you are doing accounting apps or anything dealing with money, or doing
comparisons with relops, you want decimal, not fp.
otherwise, you have problems adding .01+.01+.01, -0 not being +0 and thus
you can't compare or something like that, etc.
fp is NOT for comparison ops. decimal you can.
_____
From: James K Beard <[email protected]>
To: JonY <[email protected]>; Kai Tietz <[email protected]>
Cc: [email protected]
Sent: Wed, March 23, 2011 10:40:30 PM
Subject: Re: [Mingw-w64-public] mingw-w64 Decimal Floating Point math
It may not be as bad as you might think because trigonometric functions
become invalid for arguments with magnitude defined by the mantissa length,
not the exponent, and the exponent is removed as part of the process in log
and exponentiation operations.
James K Beard
-----Original Message-----
From: Jon [mailto:[email protected]] On Behalf Of JonY
Sent: Wednesday, March 23, 2011 9:20 PM
To: Kai Tietz
Cc: [email protected]; [email protected]; James K
Beard
Subject: Re: [Mingw-w64-public] mingw-w64 Decimal Floating Point math
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 3/24/2011 02:29, Kai Tietz wrote:
> 2011/3/23 James K Beard <[email protected]>:
>> You don't need to go to BCD to convert DFP to IEEE (regular) floating
point.
>> A single arithmetic operation directly in DFP will exceed what you do
>> to convert to IEEE floating point. I would use double precision for
>> anything up to 12 decimals of accuracy, 80-bit for another three, and
>> simply incorporate the quad precision libraries with credit (or by
>> reference, if differences in licensing are a problem) for distribution.
>>
>> Anything other than binary representation will be less efficient in
>> terms of accuracy provided by a given number of bits. By
>> illustration, base 10 requires four bits, but provides only 3.32 bits
>> (log2(10)) per digit of accuracy. The only relief from this
>> fundamental fact is use of less bits for the exponent, and in IEEE
>> floating point the size of the exponent field is minimized just about
>> to the point of diminishing returns (problems requiring workaround in
>> areas such as determinants, series and large
>> polynomials) to begin with.
>>
>> James K Beard
>
> Well, DFP <-> IEEE conversion is already present in libgcc. So you
> shouldn't need here any special implementation. I would suggest that
> you are using for 32-bit and 64-bit DFP the double type, and AFAICS
> the 80-bit IEEE should be wide enough for the 128-bit DFP. How big is
> its exponent specified? Interesting might be the rounding.
>
> Regards,
> Kai
>
Long doubles extended precision go up to 4963 (base 10) in exponent, while
DECIMAL128 go up 6144, this is assuming I didn't get the docs wrong.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.16 (MingW32)
iEYEARECAAYFAk2KnFEACgkQp56AKe10wHf30ACeKpD4YvTTR8k8pSO9njpa9pVQ
/B8An1s6P6yNV1UcTdIe6evB6VrVz9IV
=hBNq
-----END PGP SIGNATURE-----
----------------------------------------------------------------------------
--
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public