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