Boost logo

Boost :

From: Matt Hurd (matt.hurd_at_[hidden])
Date: 2004-09-26 19:35:25


> Victor A. Wagner Jr. <vawjr_at_[hidden]> wrote:
> The midpoint between them is (this is legal using your constraints):
>
> a + (b-a)/2
>
> 1st year algebra teaches us that this is equivalent to:
>
> (a+b)/2
>
> While on most systems the intermediate value (a+b) would be useless, as
> soon as you divide by 2 it again becomes useful.
>
> with a third pointer (T* c;):
>
> (a+b+c)/3
>
> becomes calculable and useful though clearly

Just a small $0.02...

(a + b) is a dangerous thing in a 32 bit world full of arithmetic
overflow opportunities. You'd have to have a very good reason for
doing it this way I'd think.

a + (a-b) / 2 is a bit safer.

matt
matthurd_at_[hidden]


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