From: Rainer Deyke (root_at_[hidden])
Date: 2001-05-09 13:50:44
----- Original Message -----
From: "Bill Seymour" <bsey_at_[hidden]>
Sent: Wednesday, May 09, 2001 11:01 AM
Subject: [boost] Fixed-Point Decimal Type
> 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.
I think there's also a need for non-decimal fixed-point numbers (i.e.
hexadecimal digits to the right of the hexadecimal point or such). For this
reason I would prefer it if there was instead a template argument N such
that multiplies of 1/N are reprsented exactly.
> - 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.)
I would make the internal representation type another template argument.
> - Support all operations that can be done on ints except implicit
> conversions and non-decimal I/O.
This statement is somewhat ambiguous. How are expressions that combine
integers and fixed-point values defined?
> - 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.)
If at all possible, I would make the rounding mode user selectable.
-- Rainer Deyke (root_at_[hidden]) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk