|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-10-24 13:30:56
From: "Fernando Cacciola" <fcacciola_at_[hidden]>
> From: Peter Dimov <pdimov_at_[hidden]>
> > I don't really see what's wrong with the simple
> >
> > namespace math
> > {
> > double const pi = 3.14159265358...;
> > }
> It doesn't fit well into generic programming:
>
> template<class Numeric>
> void foo ( Numeric angle )
> {
> if ( angle == pi ) // A narrowing conversion will occur here, if, for
> instance, Numeric is 'long double' or 'MyReallyBigFloat'
> }
The theory is sound. It's the practice that I'm not sure about. True, 'pi'
is not generic, but in my opinion, it covers 90+% of the real world use
cases quite fine, and the remaining areas will probably use their own
definitions anyway.
For example, your foo<> will most probably be specialized on 'long double'
or 'MyReallyBigFloat.' Not to mention that an equality comparison to 'pi' is
somewhat uncommon.
-- 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