diff options
Diffstat (limited to 'src/math/lgamma.c')
| -rw-r--r-- | src/math/lgamma.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/math/lgamma.c b/src/math/lgamma.c index 3612c825..3f0799c2 100644 --- a/src/math/lgamma.c +++ b/src/math/lgamma.c @@ -1,9 +1,25 @@ # define TGSOURCE "lgamma.c" #include "_tgmath.h" #include <math.h> +#include "fenv.h" TYPE TGFN(lgamma)(TYPE x) { + switch (fpclassify(x)) { + case FP_ZERO: feraiseexcept(FE_DIVBYZERO); return INFINITY; + case FP_INFINITE: return INFINITY; + default: break; + } + + if (x == 1.0 || x == 2.0) { + return 0.0; + } + + if (signbit(x)) { + feraiseexcept(FE_DIVBYZERO); + return INFINITY; + } + return x; } |
