
Boost : 
From: scleary_at_[hidden]
Date: 20010509 13:06:50
> When J16 and WG21 begin working on specific proposals for the
> evolution of C++, I intend to suggest a fixedpoint decimal type.
> The main reason is that many novices want to use floatingpoint
> types to store monetary values; and they're suprised when the
> pennies (or other fractional values) don't add up. In the
> traditional "business data processing" environment in which
> I work, this is often what Bjarne calls an "embarrassment."
Even fixedpoint values suffer from:
1) Binary representation (therefore causing approximate calculations when
dealing with decimal input, output, or arithmetic)
2) Roundoff errors
Fixedpoint arithmetic therefore shares several annoying attributes with
floatingpoint arithmetic; as an extreme example, assuming a 4bit
underlying representation (ignoring signs) with the implied decimal in the
middle:
0.1 + 0.1 != 0.2
(since there are only 2 bits for the values to the right of the decimal
point in our example, it can only represent .00, .25, .50, and .75;
therefore, "0.1" becomes equivalent to "0.00", and "0.2" becomes equivalent
to "0.25")
If the above seems too extreme, just consider dividing by 10, and realize
that an exact result can't be stored using a binaryencoded fixedpoint
number. Do enough decimal calculations, and you'll eventually slip a digit.
I'm not against fixedpoint arithmetic; I just don't think it solves the
problem.
If the intention is to help newbies by providing a class that behaves like
"textbook" (i.e., decimal) algebra, I'd rather see a C++ implementation of:
http://www2.hursley.ibm.com/decimal/
Steve
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk