View mode: basic / threaded / horizontal-split · Log in · Help
September 23, 2005
[Submission - std.math] tgamma, lgamma
-------------------
real tgamma(real x) --- returns gamma(x)

real lgamma(real x) --- returns log(abs(gamma(x))
-------------------
They come with unit tests and ddoc documentation.

Both are based on Cephes, but with much cleaner code.
Includes all the relevant unit tests from Cephes, and I've
also tested them for consistency with each other and with factorials.
Still, the coverage of the tests is not as good as I'd really like.

There's also an unoptimised
real poly(real x, real[] coeffs)
which was necessary  for implementation.

this is all in
statistical.d

realtest.d includes a function used in the unit tests.

-------------------
int consistencyTwoFuncs(real function (real) firstfunc,
                    real function (real) secondfunc, real [] domain ...)
-------------------
also a function which replaces the one in my previous submission.
(Behaviour is identical, but code is much shorter).

-------------------
int consistencyRealInverse(real function (real) forwardfunc,
                    real function (real) inversefunc, real [] domain ...)

-------------------
Contents of both files can be added as a cut-and-paste job, but since 
the gamma implementation is so long, maybe it belongs in a file other 
than std.math.

Enjoy!
-Don.
October 06, 2005
Re: [Submission - std.math] tgamma, lgamma
Thanks, I'm putting them in now. I still need your explicit permission,
though. The lawyers like it that way <g>.
October 06, 2005
Re: [Submission - std.math] tgamma, lgamma
Walter Bright wrote:
> Thanks, I'm putting them in now. I still need your explicit permission,
> though. The lawyers like it that way <g>.

You have my full and unrestricted permission for all my submitted code. 
Please put it in.
(I guess this will actually be a DMC, not a DMD update? Wierd).

For the other functions I submitted, the comments are pre-DDoc, and the
creal cis(real theta) function should be renamed as creal exp(ireal theta).

A suggestion:
math.d has a lot of stuff in it, and will only get worse with time.
This problem is inherited from C, but since #include "math.h" has to
be changed to import std.math anyway, there does not seem to be any need 
to retain it.

How about:
math.d --> elementary functions (sin, cos, sinh, exp, ln...)
   + low-level floating point functions which
     rely on the actual bit representation (isnormal, etc)
mathspecial.d --> mathematical special functions.
   (gamma, erfc, Bessel functions, the productLog() I submitted 
earlier, etc).
mathstat.d  or mathstatistic.d or statistical.d --> mathematical 
statistical functions
   (incomplete beta, normal, poisson, chi-squared, F, student t 
distributions, etc)  -- I have most of these working now, currently 
improving the unit tests and docs.

By retaining 'math' in the first part of the name it would be easy to 
find them in the docs.

I even think it could be a good idea to split off the low-level 
bit-twiddling functions into a seperate file (maybe ieee.d ?) which 
would be publicly imported by math.d. It would include the C99 functions 
that are in fenv.h as well as those from math.h. This would isolate the 
processor and OS-specific code from the strictly mathematical code, 
which would make porting easier.

-Don
October 06, 2005
Re: [Submission - std.math] tgamma, lgamma
On Thu, 06 Oct 2005 10:56:46 +0200, Don Clugston <dac@nospam.com.au> wrote:
> How about:
> math.d --> elementary functions (sin, cos, sinh, exp, ln...)
>     + low-level floating point functions which
>       rely on the actual bit representation (isnormal, etc)
> mathspecial.d --> mathematical special functions.
>     (gamma, erfc, Bessel functions, the productLog() I submitted  
> earlier, etc).
> mathstat.d  or mathstatistic.d or statistical.d --> mathematical  
> statistical functions
>     (incomplete beta, normal, poisson, chi-squared, F, student t  
> distributions, etc)  -- I have most of these working now, currently  
> improving the unit tests and docs.
>
> By retaining 'math' in the first part of the name it would be easy to  
> find them in the docs.

What you really want is:

import std.math;
import std.math.stat;
import std.math.spec;

and so on, and so forth.

But.. I don't think you can name them that way, can you?

Regan
Top | Discussion index | About this forum | D home