ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
[boost] Re: [math constants] a new approach (perhaps)
by Guillaume Melquiond other posts by this author
Mar 1 2004 10:25AM messages near this date
[boost] Re: [math constants] a new approach (perhaps) | [boost] Re: [math constants] a new approach (perhaps)
Le lun 01/03/2004 à 01:06, Thorsten Ottosen a écrit :

>  namespace std
>  {
>  
>  #define CNAME( Var ) Var##_constant_t
>  
>  #define OVERLOAD_CONTEXT( ConstType, FP, FPV )  > inline FP operator+( FP l, ConstType )  
        >  { return l + FPV; }                             > inline FP operator+( ConstType, 
FP r )          >  { return r + FPV; }                             > inline FP operator-( FP 
l, ConstType )          >  { return l - FPV; }                             > inline FP operat
or-( ConstType, FP r )          >  { return FPV - r; }                             > inline F
P operator*( FP l, ConstType )          >  { return l * FPV; }                             > 
inline FP operator*( ConstType, FP r )          >  { return r * FPV; }                       
      >  inline FP operator/( FP l, ConstType )          > { return l / FPV; }               
              >  inline FP operator/( ConstType, FP r )          > { return FPV / r; }       
                      >  
>  #define DEFINE_FP_CONSTANT( Name, FV, DV, LDV )     > struct CNAME( Name )                
                >  {                                                   >   CNAME( Name ) ()  
           {}                   >    operator float() const       { return FV; }       >   op
erator double() const      { return DV; }       >    operator long double() const { return LD
V; }      >  };                                                  > OVERLOAD_CONTEXT( CNAME( N
ame ), float, FV )        >  OVERLOAD_CONTEXT( CNAME( Name ), double, DV )       > OVERLOAD_C
ONTEXT( CNAME( Name ), long double, LDV ) >  const CNAME( Name ) Name;
>  
>  DEFINE_FP_CONSTANT( pi, 3.14F, 3.14232, 3.1423211223L )
>  
>  } // namespace std

Unless I'm missing something, it seems to me that the constants can only
be defined for built-in floating-point numbers. Indeed, once the
structure for a pi constant has been defined by DEFINE_FP_CONSTANT (in
the math_constant.hpp header), the user or others libraries cannot add
new values for their own numerical types.

With respect to that, I think the proposal of Daniel Frey is a lot more
interesting since it allows user-defined types and provides automatic
type deduction so that complex constants do not have to have their own
names. Being able to write "interval<double>  a = 2 * pi;" and being sure
it is mathematically correct and accurate is great.

Regards,

Guillaume



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Thorsten Ottosen
Thorsten Ottosen
Daniel Frey
Thorsten Ottosen
Daniel Frey
Thorsten Ottosen
Daniel Frey
Thorsten Ottosen
Guillaume Melquiond
Daniel Frey
Bronek Kozicki
Bronek Kozicki
Bronek Kozicki
Daniel Frey
Bronek Kozicki
Daniel Frey
Daniel Frey
Bronek Kozicki
Daniel Frey
Daniel Frey
Bronek Kozicki
Daniel Frey
Bronek Kozicki
Bronek Kozicki
Daniel Frey
Paul A Bristow
Paul A Bristow
Paul A Bristow
Paul A Bristow
Phil Richards
Daniel Frey
Paul A Bristow
David Abrahams
Paul A Bristow
David Abrahams

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved