|
Boost : |
From: Bill Seymour (bsey_at_[hidden])
Date: 2001-05-09 12:01:39
When J16 and WG21 begin working on specific proposals for the
evolution of C++, I intend to suggest a fixed-point decimal type.
The main reason is that many novices want to use floating-point
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."
If there's interest, I'd like to do a reference implementation
under the auspices of Boost. The requirements for the type
would be:
- A template class with the template parameter being the number
of digits to the right of the decimal point.
- Represent at least 18 decimal digits exactly. (The 18 comes
from prior art on IBM mainframes, and also turns out to be
convenient if the internal representation is a 64-bit int.)
- Support all operations that can be done on ints except implicit
conversions and non-decimal I/O.
- All operations are exact if there is no overflow and if no
rounding is required. Overflow is undefined behavior.
Rounding is done the way accountants do it: round to nearest
with 1/2-LSB always rounded "up." (I think "up" means "away
from zero." I've asked an accountant friend via e-mail but
haven't yet gotten an answer.)
- Construction from const char* for faking decimal constants.
- Explicit conversion to/from double.
Are there more requirements that I haven't thought of?
All comments and flames are welcome.
--Bill Seymour
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk