Re: Double: 2 Decimal points




"tex" <NoSpam@xxxxxxxxxxx> schreef in bericht
news:MJtHe.7982$Uk3.4229@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> It actually is the best choice. Mainframe financial applicatins are
> generally done in BCD (Binary Coded Decimal) which, at the hardware
> level, is actually integers and any decimal point is in the hand of the
> programmer (compilers, e.g. COBOL, would take care of that, but,
> underneath it is all integers, though alllowing much bigger integers than
> 32-bit integers). It is such a good way to do things that Intel included
> BCD with the 8088 in the 1st PCs and its still avl in todays chips.
> Years ago, I was shocked to find spreadsheets (heavily used in financial
> calcs) using floating pt, and also dismayed in C's not supporting BCD
> as a native data type. Borland's Delphi includes a $-type which, by
> default
> assumes 4 digits of decimal, and it supports a BCD object that lets
> users select the precision, but, underneath it is all integers.

One problem I have with this is that (1.0 / 3.0) + (1.0 / 3.0) + (1.0 / 3.0)
and ((1.0 + 1.0 + 1.0)/ 3.0) have a result that differs by 10%, and that my
experience is that the compiler doesn't always catch that, and that
mainframe programmers don't always think about that.

Another problem with BCD is that the decimal representation is rather
arbitrary (based on the number of fingers a mathematician in ancient India
happened to have had), and thus causes a lot of extra overhead for the CPU.

By the way, there are some excellent big decimal libraries available for C.
http://www.gnu.org/software/gmp/


.