|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-10-24 14:35:14
From: "Greg Colvin" <gcolvin_at_[hidden]>
> From: Peter Dimov <pdimov_at_[hidden]>
> > From: "Greg Colvin" <gcolvin_at_[hidden]>
> > > From: Peter Dimov <pdimov_at_[hidden]>
> > > > float const pi_f = math::pi;
> > >
> > > I think on Noah's system this will result in the value in double const
pi
> > > being converted, slowly, at runtime.
> >
> > Once, at startup. If this is really a problem, we can (and probably
should)
> > add pi_f (and pi_l) to math:: as well.
>
> Once in this case. But take away the const and put the initialization
> in block scope ...
Why should I do that? :-)
> > The question is, what is the value of providing a generic framework that
can
> > handle types that we don't know about.
>
> Well, the advantage of fetching the constants via an
> inline function is that it is faster,
"Prettier" assembly doesn't mean faster. It might well be faster, or it
might be slower. I didn't see any timings for a nontrivial program being
posted?
> and that an more
> precise implementation might be possible, e.g. with an
> extension for hexadecimal literals.
More precise implementations are possible:
namespace math
{
union _Pi_t
{
unsigned char x[8];
double y;
};
_Pi_t _Pi = { 0xB8, ... };
double const & pi = _Pi.y;
}
or whatever other ugly platform-specific hacks are necessary.
-- 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