Boost logo

Boost :

From: John Max Skaller (skaller_at_[hidden])
Date: 2001-05-09 13:45:30


Bill Seymour wrote:

> If there's interest, I'd like to do a reference implementation
> under the auspices of Boost.

        Yes, this is a very good idea.

> - Support all operations that can be done on ints except implicit
> conversions and non-decimal I/O.

        This is overkill: you need to support add, subtract,
negate, multiply, divide and remainder, and abs.

        You do not need to support bitmask operations or
bitwise shifts. On the other hand you will need shifting the
decimal point by a constant: this is NOT the same as
multiply or divide by a power of 10.

        [It is common, for example, to shift a 'dollar' amount
into 'cents', or perhaps 'points' (1/10 cent) and back].
 
> - 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.)

        This is problematic. For some operations, it is
wrong to always round 1/2 LSD up: when doing statistical
operations, rounding up or down at random is correct.
Sometimes, truncation is correct (rather than rounding).

        This suggests that you pick one mode (as you have)
for the operator?? forms, but supply the other operations
as named functions, for example

        mul_with_truncate(a,b)
        mul_with_rhlsd_up(a,b)
        mul_with_rhlsd_ran(a,b)
        mul_with_noround(a,b)
 
> - Construction from const char* for faking decimal constants.

        Why not (also) from 'string', to support
input conversions? How will you handle errors?

        Also, you will need an output-to-string routine.
How will the output be formatted? If you really want
to support currency operations, COBOL style picture formatting
is the way to go. That is possibly right for input too.
Some 'locale' information is then useful as well.

        It is also OK to leave this stuff out: a basic
library is better than none, and much better than
getting it completely wrong :-)
 

-- 
John (Max) Skaller, mailto:skaller_at_[hidden]
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk