
Boost : 
From: Paul A. Bristow (boost_at_[hidden])
Date: 20011025 04:39:41
This too looks rather interesting.
Would you like to work this up to demo the various ways of using it
(similar to my demo in vault of Michael's original suggestion).
We need to show how the simple double area = pi * r * r;
will work, as well as getting the various real sizes.
(And we need to repeat the efficiency and bloat checks.
Is the constructor essential  I fear linker bloat,
as found for MSVC on the previous example.)
Extension to other types (complex?) is valuable.
rational is a good example  and sorts the nerds who
can pull pi as a rational off the top of their head
from we lesser mortals!
Paul
PS Or would you like me to?
Dr Paul A Bristow, hetp Chromatography
Prizet Farmhouse
Kendal, Cumbria
LA8 8AB UK
+44 1539 561830
Mobile +44 7714 33 02 04
mailto:pbristow_at_[hidden]
> Original Message
> From: Greg Colvin [mailto:gcolvin_at_[hidden]]
> Sent: Thursday, October 25, 2001 5:37 AM
> To: boost_at_[hidden]
> Subject: Re: [boost] Math constants for naive and gurus?  which
> constants do you want?
>
>
> Here is yet another suggestion. It allows most users to just write
> v = pi
> and get a pretty good approximation to pi, and pronto.
>
> And it allows generic programmers to write things like:
>
> template<typename T> mashed_pi() {
> return mash(constant<T>(pi));
> }
>
> And it allows boost::math::constants library implementors to provide
> specializations that are faster, more precise, or whatever.
>
> And it provides a pattern for other numeric libraries to take advantage
> of, e.g.:
>
> template<> inline rational<int> constant(const pi_&) {
> return rational<int>(5419351,1725033);
> }
>
> Here is a sketch of an implementation:
>
> namespace constants {
>
> // an example constant, suitable for everyday abuse
> static const struct pi_ {
> pi_(){}
> inline operator long double() const {
> return 3.141592653589793238462643383279502884197L;
> }
> } pi;
>
> // a generic constant generator
> template<typename T, typename V> inline T constant(const V& v) {
> return static_cast<T>(v);
> }
>
> // example specializations of the constant generator
> template<> inline float constant(const pi_&) {
> return 3.141593F;
> }
> template<> inline double constant(const pi_&) {
> return 3.14159265358979;
> }
> template<> inline long double constant(const pi_&) {
> return 3.141592653589793238L;
> }
> }
>
>
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boostunsubscribe_at_[hidden]>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk