Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2005-09-30 05:10:29


> In Mathematical Special Functions, why are the functions not template
> specialisations?

You would have to ask the original author of that section, but I believe it
was C compatibility.

There is also the issue that many of these functions can only be implemented
efficiently if you know the precission of the argument type up front, so the
float/double/long double versions would have different implementations in
any case (different Chebyshev polynomial approximations for example) and
there would be no "generic" implementation readily possible.

I've also found that some well known formula can fail quite spectacularly
once the compilers optimisations are turned on: either through double
rounding of long double intermediates, or through non IEEE arithmetic
optimisations. This makes implementing many mathematical functions as
templates error prone - because you have no control over the compilation
environment - where as separate file compilation effectly solves that issue,
albeit in a compiler specific manner. See the proposed log1p implementation
(and associated code comments) for one particularly fustrating, if trivial
example.

I realise you're suggesting template specialisations rather than a generic
template, but if there is no generic template provided, what advantages do
specialisations provide over regular overloads?

John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net