
Boost : 
From: Gabriel Dos Reis (Gabriel.DosReis_at_[hidden])
Date: 20010525 05:51:20
John Max Skaller <skaller_at_[hidden]> writes:
 Gabriel Dos Reis wrote:

 >  I don't see that the rounding mode is a property of the data,
 >  it is property of each individual operation.
 >
 > No. Rounding is the act of taking an exact result and producing an
 > approximation within the range of numerical datatype; that is a
 > function defined on a superset of the actual datatype, with values in
 > the set of values of the datatype. It is independent of individual
 > operations.

 I don't think this works. Just consider

 decimal<n> * decimal<m>

 There is no 'universal' way to round the results.
That is why I didn't propose something to that effect. As, I
mentionned, rounding is part of the datatype manipulated.
My proposal is about
decimal<n, nearest> * decimal<n, nearest>
You can make nearest the default rounding mode, in which case, it
reads
deciaml<n> * decimal<n>;
If you want to multiply two numbers with different precision, you need
to make it explicit which precision you want.
 ... The scale
 of the result depends on the arguments AND the operation.
 What you seem to be suggesting is a pair of maps:

 LIFT: decimal<n> > exact decimal
 ROUND: exact decimal > decimal<n>

 But actually, there is a family of maps:

 ROUND<n>: exact decimal > decimal<n>

 and the choice of which ROUND map to use
 _depends on the operation_ being performed.
 It will differ for addition and multiplication.
I think you misunderstand how the LIA model works.
Let's take mul : decimal<n> * decimal<n> > decimal<n>.
The result is computed as if:
1) an exact multiplication is performed, yielding an exact result
(decimal<2*n>).
2) and the rounding function is invoked to project the result in
decimal<n>.
That is no more different than the conceptual model of IEEE754.
And no, the model doesn't fail for division and al..
 Gaby
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk