@@ -74,6 +74,17 @@ static const double pi = 3.141592653589793238462643383279502884197;
74
74
static const double sqrtpi = 1.772453850905516027298167483341145182798 ;
75
75
static const double logpi = 1.144729885849400174143427351353058711647 ;
76
76
77
+ #ifndef __APPLE__
78
+ # ifdef HAVE_TGAMMA
79
+ # define USE_TGAMMA
80
+ # endif
81
+ # ifdef HAVE_LGAMMA
82
+ # define USE_LGAMMA
83
+ # endif
84
+ #endif
85
+
86
+ #if !defined(USE_TGAMMA ) || !defined(USE_LGAMMA )
87
+
77
88
static double
78
89
sinpi (double x )
79
90
{
@@ -230,6 +241,7 @@ lanczos_sum(double x)
230
241
}
231
242
return num /den ;
232
243
}
244
+ #endif /* !defined(USE_TGAMMA) || !defined(USE_LGAMMA) */
233
245
234
246
/* Constant for +infinity, generated in the same way as float('inf'). */
235
247
@@ -263,6 +275,14 @@ m_nan(void)
263
275
static double
264
276
m_tgamma (double x )
265
277
{
278
+ #ifdef USE_TGAMMA
279
+ if (x == 0.0 ) {
280
+ errno = EDOM ;
281
+ /* tgamma(+-0.0) = +-inf, divide-by-zero */
282
+ return copysign (Py_HUGE_VAL , x );
283
+ }
284
+ return tgamma (x );
285
+ #else
266
286
double absx , r , y , z , sqrtpow ;
267
287
268
288
/* special cases */
@@ -354,6 +374,7 @@ m_tgamma(double x)
354
374
if (Py_IS_INFINITY (r ))
355
375
errno = ERANGE ;
356
376
return r ;
377
+ #endif
357
378
}
358
379
359
380
/*
@@ -364,7 +385,17 @@ m_tgamma(double x)
364
385
static double
365
386
m_lgamma (double x )
366
387
{
367
- double r , absx ;
388
+ double r ;
389
+
390
+ #ifdef USE_LGAMMA
391
+ r = lgamma (x );
392
+ if (errno == ERANGE && x == floor (x ) && x <= 0.0 ) {
393
+ errno = EDOM ; /* lgamma(n) = inf, divide-by-zero for */
394
+ return Py_HUGE_VAL ; /* integers n <= 0 */
395
+ }
396
+ return r ;
397
+ #else
398
+ double absx ;
368
399
369
400
/* special cases */
370
401
if (!Py_IS_FINITE (x )) {
@@ -402,8 +433,11 @@ m_lgamma(double x)
402
433
if (Py_IS_INFINITY (r ))
403
434
errno = ERANGE ;
404
435
return r ;
436
+ #endif
405
437
}
406
438
439
+ #if !defined(HAVE_ERF ) || !defined(HAVE_ERFC )
440
+
407
441
/*
408
442
Implementations of the error function erf(x) and the complementary error
409
443
function erfc(x).
@@ -513,11 +547,16 @@ m_erfc_contfrac(double x)
513
547
return result ;
514
548
}
515
549
550
+ #endif /* !defined(HAVE_ERF) || !defined(HAVE_ERFC) */
551
+
516
552
/* Error function erf(x), for general x */
517
553
518
554
static double
519
555
m_erf (double x )
520
556
{
557
+ #ifdef HAVE_ERF
558
+ return erf (x );
559
+ #else
521
560
double absx , cf ;
522
561
523
562
if (Py_IS_NAN (x ))
@@ -529,13 +568,17 @@ m_erf(double x)
529
568
cf = m_erfc_contfrac (absx );
530
569
return x > 0.0 ? 1.0 - cf : cf - 1.0 ;
531
570
}
571
+ #endif
532
572
}
533
573
534
574
/* Complementary error function erfc(x), for general x. */
535
575
536
576
static double
537
577
m_erfc (double x )
538
578
{
579
+ #ifdef HAVE_ERFC
580
+ return erfc (x );
581
+ #else
539
582
double absx , cf ;
540
583
541
584
if (Py_IS_NAN (x ))
@@ -547,6 +590,7 @@ m_erfc(double x)
547
590
cf = m_erfc_contfrac (absx );
548
591
return x > 0.0 ? cf : 2.0 - cf ;
549
592
}
593
+ #endif
550
594
}
551
595
552
596
/*
0 commit comments