www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - lgamma & gamma reentrant

reply Travis Boucher <boucher.travis gmail.com> writes:
I need some feedback from some of the math nerds on the list.

The functions gammaf and lgammaf are not reentrant and set a global 
'signgam' to indicate the sign.

Currently it looks like druntime/phobos2 use these non-reentrant 
versions, which could cause some issues in a threaded environment.

My questions for the math nerds are:

How important is this signgam value?

Should we provide a safe way of getting this value?

In std.math should we wrap the reentrant versions and store signgam in 
TLS, or should we expose the *_r reentrant versions in std.math directly?

I think now in D2 global variables are stored thread-local by default, 
so providing a safe signgam would be trivial (of course only accessible 
to the thread that called the lgamma/gamma).

Another option is to just leave it alone.  Personally I couldn't care 
less since I have never used the functions.

-- tbone
Jan 05 2011
parent "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> writes:
On Wed, 05 Jan 2011 11:33:30 -0700, Travis Boucher wrote:

 I need some feedback from some of the math nerds on the list.
 
 The functions gammaf and lgammaf are not reentrant and set a global
 'signgam' to indicate the sign.
 
 Currently it looks like druntime/phobos2 use these non-reentrant
 versions, which could cause some issues in a threaded environment.
 
 My questions for the math nerds are:
 
 How important is this signgam value?
 
 Should we provide a safe way of getting this value?
 
 In std.math should we wrap the reentrant versions and store signgam in
 TLS, or should we expose the *_r reentrant versions in std.math
 directly?
 
 I think now in D2 global variables are stored thread-local by default,
 so providing a safe signgam would be trivial (of course only accessible
 to the thread that called the lgamma/gamma).
 
 Another option is to just leave it alone.  Personally I couldn't care
 less since I have never used the functions.
 
 -- tbone

Phobos does not use the C gamma functions anymore. Instead, there are native D implementations in the std.mathspecial module (as of the latest release), that don't have this problem. See: http://www.digitalmars.com/d/2.0/phobos/std_mathspecial.html http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/ mathspecial.d -Lars
Jan 05 2011