This math scares me
Grant Edwards
grante at visi.com
Wed Mar 14 16:31:54 EST 2001
In article <98oku1$f6a$1 at news.udel.edu>, Terry Reedy wrote:
>
>"Grant Edwards" <grante at visi.com> wrote in message
>news:7bQr6.644$lz1.17686 at ruti.visi.com...
>> In article <98ohuc$du9$1 at news.udel.edu>, Terry Reedy wrote:
>>
>> >> Bill Gates got this right in the early days, delivering two
>> >> Basic interpreters: binary floating point for speed, and
>> >> decimal floating point for money and such
>> >
>> >If one counts pennies instead of dollars, then 32 bit ints (+-
>> >$20 million) will serve for many purposes. Exact, faster, and
>> >more widely available than BCD
>>
>> In fiancial calculations you also need to represent numbers
>> that aren't amounts of money. Interest rates for example.
>
>So?
So 32 bit integers with a weighting of one penny per count
won't work for that.
>Floats (double precision) work well enough for this, I believe.
No. The binary floating point representation of many decimal
fraction values is not exact. That's what started this whole
thread. You can't represent 0.1 exactly in binary FP. You can
in BCD.
>Note that binary fraction stock prices are exact with floats
>and not with BCD.
Wrong.
1/16 is exactly represented in BCD as 0.0625. 1/32 is 0.03125,
and so on. Some other fractions (e.g. 1/3) are not exactly
representable by BCD, but all the fractions used on exchanges
are all powers of 1/2 and can be represented exactly in BCD.
I believe that there are plans (on some exchanges) to switch
pricing from base-2 fractions to decimal fractions.
--
Grant Edwards grante Yow! Now I can join WEIGHT
at WATCHERS!
visi.com
More information about the Python-list
mailing list