Skip to content

Commit b6cd898

Browse files
committed
Don't let tgammal() modify signgam. Only lgamma*() should modify it.
Letting tgammal() modify signgam has two disadvantages: - It breaks valid code that assumes that the value of signgam is not clobbered by calls to tgammal(). - It makes this function depend on the presence of signgam. signgam is an X/Open System Interface. It is not part of the C standard.
1 parent 0b2a647 commit b6cd898

2 files changed

Lines changed: 9 additions & 22 deletions

File tree

ld128/e_tgammal.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,14 @@ tgammal(long double x)
2626
int64_t i0,i1;
2727

2828
GET_LDOUBLE_WORDS64(i0,i1,x);
29-
if (((i0&0x7fffffffffffffffLL)|i1) == 0) {
30-
signgam = 0;
29+
if (((i0&0x7fffffffffffffffLL)|i1) == 0)
3130
return (1.0/x);
32-
}
3331

34-
if (i0<0 && (u_int64_t)i0<0xffff000000000000ULL && rintl(x)==x) {
35-
signgam = 0;
32+
if (i0<0 && (u_int64_t)i0<0xffff000000000000ULL && rintl(x)==x)
3633
return (x-x)/(x-x);
37-
}
3834

39-
if (i0==0xffff000000000000ULL && i1==0) {
40-
signgam = 0;
35+
if (i0==0xffff000000000000ULL && i1==0)
4136
return (x-x);
42-
}
4337

4438
return expl(lgammal(x));
4539
}

ld80/e_tgammal.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@
2525
* SYNOPSIS:
2626
*
2727
* long double x, y, tgammal();
28-
* extern int signgam;
2928
*
3029
* y = tgammal( x );
3130
*
3231
*
3332
*
3433
* DESCRIPTION:
3534
*
36-
* Returns gamma function of the argument. The result is
37-
* correctly signed, and the sign (+1 or -1) is also
38-
* returned in a global (extern) variable named signgam.
39-
* This variable is also filled in by the logarithmic gamma
35+
* Returns gamma function of the argument. The result is correctly
36+
* signed. This variable is also filled in by the logarithmic gamma
4037
* function lgamma().
4138
*
4239
* Arguments |x| <= 13 are reduced by recurrence and the function
@@ -61,7 +58,6 @@
6158
#include <openlibm.h>
6259

6360
#include "math_private.h"
64-
extern int signgam;
6561

6662
/*
6763
tgamma(x+2) = tgamma(x+2) P(x)/Q(x)
@@ -224,7 +220,6 @@ tgammal(long double x)
224220
long double p, q, z;
225221
int i;
226222

227-
signgam = 1;
228223
if( isnan(x) )
229224
return(NAN);
230225
if(x == INFINITY)
@@ -237,6 +232,7 @@ q = fabsl(x);
237232

238233
if( q > 13.0L )
239234
{
235+
int sign = 1;
240236
if( q > MAXGAML )
241237
goto goverf;
242238
if( x < 0.0L )
@@ -246,7 +242,7 @@ if( q > 13.0L )
246242
return (x - x) / (x - x);
247243
i = p;
248244
if( (i & 1) == 0 )
249-
signgam = -1;
245+
sign = -1;
250246
z = q - p;
251247
if( z > 0.5L )
252248
{
@@ -258,15 +254,15 @@ if( q > 13.0L )
258254
if( z <= PIL/LDBL_MAX )
259255
{
260256
goverf:
261-
return( signgam * INFINITY);
257+
return( sign * INFINITY);
262258
}
263259
z = PIL/z;
264260
}
265261
else
266262
{
267263
z = stirf(x);
268264
}
269-
return( signgam * z );
265+
return( sign * z );
270266
}
271267

272268
z = 1.0L;
@@ -298,8 +294,6 @@ x -= 2.0L;
298294
p = __polevll( x, P, 7 );
299295
q = __polevll( x, Q, 8 );
300296
z = z * p / q;
301-
if( z < 0 )
302-
signgam = -1;
303297
return z;
304298

305299
small:
@@ -311,7 +305,6 @@ else
311305
{
312306
x = -x;
313307
q = z / (x * __polevll( x, SN, 8 ));
314-
signgam = -1;
315308
}
316309
else
317310
q = z / (x * __polevll( x, S, 8 ));

0 commit comments

Comments
 (0)