This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: FW: Special functions in TR1



-----Original Message-----
From: Theodore Papadopoulo [mailto:Theodore.Papadopoulo@sophia.inria.fr] 
Sent: Wednesday, November 30, 2005 2:09 PM
To: Smith-Rowland, Edward M (Contractor)
Cc: 'libstdc++@gcc.gnu.org'
Subject: Re: FW: Special functions in TR1

On Wed, 2005-11-30 at 12:23 -0500, Smith-Rowland, Edward M (Contractor)
wrote:

> 6. The GSL methods and variables should probably not be in the global
> namespace - we would want to put them into a namespace that wouldn't
collide
> or be visible: std::tr1::__gsl?

> Is anyone else thinking about this?

Well, I gave some thought on this a few months ago. I even implemented
the simple algorithms for some of the functions (but these certainly
have some numerical problems for some of the inputs). Then, I had a look
at gsl's implementations....

Personnaly, I would find much more interesting to re-write (and
simplify) the gsl routines and take advantage of C++, instead of
importing them. Typically, templates can be used to commonize most of
the float/double/... paths and exceptions (I do not remember if TR1
allows them but it should) are a much nicer way to signal problems
instead of error codes.

That being said I do not have advanced much further than that....
But if we have similar ideas, maybe I can help...

	Theo.


------

The interface as specified by the TR1 draft is pretty C-like (there seems to
be an effort to make C++ somewhat compatible with C). Each function has
variants func(double), funcf(float), and funcl(long double) along with
overloads of the double functions for float and long double arguments (i.e.
without the 'f' and 'l' suffixes).  On the other hand, we could call a
template function internally and put all the work in one routine for each
function.


Here's a schematic:

template< typename Numeric >
Numeric __func( Numeric x )
{
  if ( ! std::tr1::is_floating_point< Numeric >::value )
    {
      throw std::domain_error;
    }

  if ( sizeof( Numeric ) == sizeof( double )
    {
      //  Initialize for double algorithm.
    }

  ...
}

double func( double x ) { return __func( x ) };
float funcf( float x ) { return __func( x ) };;
long double funcl( long double x ) { return __func( x ) };;

Often you need constants of different numeric types and different numbers of
iterations for different accuracies and numeric types.  We could use type
traits (I think these are going into TR1 also) to tell which numeric type we
have so we don't have to have explicit template specializations.

About returns and exceptions: The TR1 draft says that if any argument is NaN
just return NaN with no error.  If an input is a valid number but is out of
range throw std::domain_error.

BTW, the draft is here:
www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1745.pdf

This could be interesting!

Ed


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]