1*49393c00Smartynas /* $OpenBSD: e_tgammal.c,v 1.1 2011/07/06 00:02:42 martynas Exp $ */
2*49393c00Smartynas
3*49393c00Smartynas /*
4*49393c00Smartynas * Copyright (c) 2011 Martynas Venckus <martynas@openbsd.org>
5*49393c00Smartynas *
6*49393c00Smartynas * Permission to use, copy, modify, and distribute this software for any
7*49393c00Smartynas * purpose with or without fee is hereby granted, provided that the above
8*49393c00Smartynas * copyright notice and this permission notice appear in all copies.
9*49393c00Smartynas *
10*49393c00Smartynas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11*49393c00Smartynas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12*49393c00Smartynas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13*49393c00Smartynas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14*49393c00Smartynas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15*49393c00Smartynas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16*49393c00Smartynas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*49393c00Smartynas */
18*49393c00Smartynas
19*49393c00Smartynas #include <math.h>
20*49393c00Smartynas
21*49393c00Smartynas #include "math_private.h"
22*49393c00Smartynas
23*49393c00Smartynas long double
tgammal(long double x)24*49393c00Smartynas tgammal(long double x)
25*49393c00Smartynas {
26*49393c00Smartynas int64_t i0,i1;
27*49393c00Smartynas
28*49393c00Smartynas GET_LDOUBLE_WORDS64(i0,i1,x);
29*49393c00Smartynas if (((i0&0x7fffffffffffffffLL)|i1) == 0) {
30*49393c00Smartynas signgam = 0;
31*49393c00Smartynas return (1.0/x);
32*49393c00Smartynas }
33*49393c00Smartynas
34*49393c00Smartynas if (i0<0 && (u_int64_t)i0<0xffff000000000000ULL && rintl(x)==x) {
35*49393c00Smartynas signgam = 0;
36*49393c00Smartynas return (x-x)/(x-x);
37*49393c00Smartynas }
38*49393c00Smartynas
39*49393c00Smartynas if (i0==0xffff000000000000ULL && i1==0) {
40*49393c00Smartynas signgam = 0;
41*49393c00Smartynas return (x-x);
42*49393c00Smartynas }
43*49393c00Smartynas
44*49393c00Smartynas return expl(lgammal(x));
45*49393c00Smartynas }
46