[phobos] Proposed changes to std.math + introduce std.mathspecial

Lars Tandle Kyllingstad lars at kyllingen.net
Thu Nov 18 06:23:07 PST 2010


On Thu, 2010-11-18 at 14:29 +0100, Don Clugston wrote:
> On 18 November 2010 12:40, Lars Tandle Kyllingstad <lars at kyllingen.net> wrote:
> > On Thu, 2010-11-18 at 12:06 +0100, Lars Tandle Kyllingstad wrote:
> >> On Wed, 2010-11-17 at 22:09 +0100, Don Clugston wrote:
> >>
> >> > (2) Delete etc.gamma
> >>
> >> I didn't even know this module existed.  I recently implemented the
> >> gamma function myself, based on the same source (Cephes).  If I'd known
> >> about this it would have saved me quite a bit of time, so I say yes,
> >> let's bring it out of hiding.
> >
> > Well, how about that -- it seems I would have saved even more time by
> > realising that there is a tgamma() function in std.math already... :p
> > (It seems to be slightly less accurate than the Cephes one, though, as
> > it doesn't pass the unittests I wrote for my implementation.)
> 
> Really? It started life as the Cephes one. I ported it to D, then
> Walter ported it back to C and put in the C standard library, where it
> is called from D (!) If you find a case where it fails, please let me
> know.

These are the unittests that failed when I tried with std.math.tgamma().
As you see, they pass with the D version in etc.


import etc.gamma, std.math;

alias etc.gamma.tgamma etcGamma;
alias std.math.tgamma  stdGamma;

void main()
{
    // Smallish argument, tested to the accuracy claimed by
    // the Cephes documentation.
    enum gamma20 = 1.2164510040883200000e17L;
    assert (approxEqual(etcGamma(20.0L), gamma20, 3.6e-19L));
    assert (approxEqual(stdGamma(20.0L), gamma20, 3.6e-19L)); //fails

    // Very large argument, tested to an accuracy which is
    // lower than the one claimed by the Cephes documentation.
    enum gammaLarge = 9.3775451196074554961e4929L;
    assert (approxEqual(etcGamma(1754.9L), gammaLarge, 1e-15L));
    assert (approxEqual(stdGamma(1754.9L), gammaLarge, 1e-15L)); //fails
}


> I have D ports of pretty much all of Cephes. The main value I added is
> unit tests to get high code coverage (well over 90%).

Really?  I am very interested!  Do you have it in a public repo
somewhere?

-Lars



More information about the phobos mailing list