Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-05-09 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] Fixed-Point Decimal Type

> John Max Skaller wrote:
> >
> > scleary_at_[hidden] wrote:
> >
> > > Fixed-point arithmetic therefore shares several annoying attributes
with
> > > floating-point arithmetic; as an extreme example, assuming a 4-bit
> > > 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 fixed-size 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, fixed-point formats never present cancellation since they fractional
points don't have to be aligned.
This is what peter means with the statement that fixed-point operations are
always exact or overflow.

Strictly speaking, fixed-point 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 fixed-size fixed-point 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