Boost logo

Boost :

From: k.hagan_at_[hidden]
Date: 2001-05-08 04:58:05


Paul Bristow wrote...
> I don't how to get down to just pi [...] so one can write
>
> double area = pi * r * r;
>
> User who are naive and experts who value clarity
> both will demand this.
> [snip]
> Writing
> boost::math::constants<const double>::pi
> is just too much
> pi<const double> is just bearable,
> but it should be possible to disguise it and write just pi.

I think we hit the buffers here. I agree that naive users will
want to be able to say just "pi", but those who want the maths
constants to be extensible to non-floating-point types will
want just "pi" to be ambiguous. (If "r" is a float, did you
want "pi" to be float, double, or long double?)

My suggestion that pi should be a class (with user defined
conversion to the desired types) lets you get down to

    double area = double(pi) * r * r;

but I would struggle to remove that final type conversion.

Perhaps the "pi" class could participate in some expression
template system, and "pi * r" could be recognised as a request
for "the same type as r". I lack the experience to know if
this idea has any legs. (It might just be a hilarious example
of over-engineering.)


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