$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Thorsten Ottosen (tottosen_at_[hidden])
Date: 2002-09-27 09:09:56
"Jason D Schmidt" <jd.schmidt_at_[hidden]> wrote in message
news:20020926.222854.3672.1.jd.schmidt_at_juno.com...
> Hi everyone,
>
> Not too long ago, I asked people on this list if anyone was interested in
> having math & physics values incorporated into Boost.  Some people
> sounded interested, so here's what I'm proposing:
>
> template <class value_type>
> struct math_vals
> {
>     static value_type pi()
>     {   return value_type(3.14); } // I'll use more digits
>     static value_type e()
>     {    return value_type(2.72); }
>     // more math values
> };
>
> Something like that.  I'll get the actual values from a reliable
> reference and use as many digits as possible.  I figure this is pretty
> simple, efficient, & portable.  Maybe if someone thinks this is a little
> verbose, he/she could do something like this in user code:
>     const float e = math_vals<float>::e();
>
> I could also do the same thing with physics-related values, like speed of
> light, Planck's constant, & more.  However, those all have units, so
> their values depend on what system we're using.  Would we want to just
> stick with SI units?  Or might we want to have another struct for cgs
> (esu) units?  Or would we want to have a units class that acts something
> like a policy?
>
> Does anyone have any thoughts on the general design I've proposed above
> or anything else?
I think that constants are really needed and your propasal is great. I
wonder if the term 'math_val' is good, though.
What about
math<float>::e();
or
constant<float>::e();
? I also wonder if we could get rid of the explicit type parameter. That is,
why shouldn't we just say
float f   = math::e();
double  = math::e();
That would reduce the hardcoding of precision. I could imagine an
implementation like this:
struct E
{
  operator float() const
{
   return <e with single precision>;
   }
 operator double() const
{
  return <e with double precisoin>;
}
};
struct math
{
 static E e() { return E(); }
};
Have I overloked something? As for different units, maybe one should choose
SI units as a default and provide means for getting other units if needed.
Thorsten Ottosen,
Dezide Aps, www.dezide.com