
Boost : 
From: Hubert HOLIN (Hubert.Holin_at_[hidden])
Date: 20010525 17:36:02
Paris (U.E.), le 26/05/2001
 In boost_at_y..., lums_at_l... wrote:
> Just a quick reply to the overflow question. One way to handle this
> is to find the largest of ar, br, cr, dr, scale them all by that
> value, compute the scaled denominator, compute the scaled at, bt, ct,
> dt, and then rescale the results.
>
> If I count correctly, there are three comparisons, four divides, and
> one more multiply introduced.
>
> Actually, to do this a little better, one would want to compute
> inverse quantities and do multiplies rather than divides throughout.
> Then there would be three comparisons, one divide, and six more
> multiplies introduced to deal with the overflow issue. The original
> method should be modified to include one divide and four multiplies
> rather than four divides. This is all assuming the basic type of the
> quaternion is something the compiler/cpu would deal with efficiently.
>
> I would produce an example, but my interface to boost is via yahoo
> groups and it is quite a pain to put code in. I hope the explanation
> conveys the right idea.
>
>
>  In boost_at_y..., Peter Schmitteckert (boost) <boost_at_s...> wrote:
> > Salut,
[SNIP]
> > Quaternions:
> > ===========
> >
> > There seem to be problem with unneccessary overflows,
> > but I didn't have the time to look into detail:
> >
> > template<typename X>
> \
> > quaternion<type> & operator /= (quaternion<X> const &
> rhs) \
> > {
> \
> > type ar = static_cast<type>(rhs.R_component_1());
> \
> > type br = static_cast<type>(rhs.R_component_2());
> \
> > type cr = static_cast<type>(rhs.R_component_3());
> \
> > type dr = static_cast<type>(rhs.R_component_4());
> \
> >
> \
> > type denominator = ar*ar+br*br+cr*cr+dr*dr;
> \
> >
> \
> > type at = (+a*ar+b*br+c*cr+d*dr)/denominator;
> \
> > type bt = (a*br+b*arc*dr+d*cr)/denominator;
> \
> > type ct = (a*cr+b*dr+c*ard*br)/denominator;
> \
> > type dt = (a*drb*cr+c*br+d*ar)/denominator;
> \
> >
>
> \
> > a = at;
> \
> > b = bt;
> \
> > c = ct;
> \
> > d = dt;
> \
> >
> \
> > return(*this);
> \
> > }
> >
> > Can this and similar expressions be reorganized to avoid overflows
> if
> > at,bt,ct,dt ? If this is not done for speed reasons, it should be
> noted,
> > that there is a danger of overflow in the denominator, allthough
> the result
> > itself won't overflow.
> >
> > Best wishes,
> > Peter
OK. Will be done (minor performance hit, but worth it).
Hubert Holin
Hubert.Holin_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk