
Boost : 
From: Peter Dimov (pdimov_at_[hidden])
Date: 20011107 07:28:56
From: "Ed Brey" <edbrey_at_[hidden]>
> From: "Peter Dimov" <pdimov_at_[hidden]>
>
> > [...]
> > > 1. Many constants are the return values of functions taking a certain
> > parameter. In a perfect world, these wouldn't be constants at all, but
> > would simply be written sqrt(2) or gamma(1/3.), or the like.
> >
> > sqrt(2) can be done by a boost::sqrt(int) that checks for the constants
it
> > recognizes. The rest will be computed on the fly.
>
> I thought about that, but it leads to the problem of the user needing to
know whether to use boost::sqrt or std::sqrt, since each would be faster in
its own situation.
No, std::sqrt fails for ints. boost::sqrt(float/double/etc) would simply
call std::sqrt (since equality comparisons on FP numbers are unreliable.)
boost::sqrt(int) would check for 'magic' numbers (i.e. argument is in [0,
512).)
The check will usually be faster than the int > double conversion.
Of course now we have the problem with the return type of boost::sqrt(int).
;)
 Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk