
Boost : 
From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 20010509 18:43:17
 Original Message 
From: Peter Bell <pbell_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, May 09, 2001 7:47 PM
Subject: Re: [boost] FixedPoint Decimal Type
> John Max Skaller wrote:
> >
> > scleary_at_[hidden] wrote:
> >
> > > 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
> >
> > This is not true for fixed point. Addition and subtraction
> > are always exact (or overflow).
> >
> [... much deleted ...]
>
> I think there is some confusion here. John is talking about *decimal*
fixed point,
> and Steve about *binary* fixed point, so both are correct :)
>
I think we need to revise some issues in order to put this discussion under
perspective:
There are different sources of inaccuracy in a computation involving
computer represented numbers.
Consider fixedsize real number formats (whether floating or fixed point).
Addition (subtraction and multiplication indeed) may produce overflow or
CANCELLATION.
Division may produce underflow or inexact result.
Cancellation is what happens when two *floating*point numbers with
different exponents (indeed, different point positions), are
operated.
Since operands must be aligned, significant digits might be shifted away and
lost.
This is what Bill was referring to with 'pennies don't add up'.
Now, fixedpoint formats never present cancellation since they fractional
points don't have to be aligned.
This is what peter means with the statement that fixedpoint operations are
always exact or overflow.
Strictly speaking, fixedpoint is exact w.r.t to addition without overflow.
As John pointed out this is not the same as
*truly* exact.
This behavior is not a property of the base (decimal or binary) but of the
choice of fixedsize fixedpoint representation.
It should be made clear that fixed<> is not exact in the general sense.
We should use fractional representations if we need that:
number = i + n/d; were a,n and d are arbitrary length integers.
But that's another story.
Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk