fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libm / math / w_lgamma.c
blobe56e477673c9264f49641ac6eb06762e707dadcc
2 /* @(#)w_lgamma.c 5.1 93/09/24 */
3 /*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
15 /* double lgamma(double x)
16 * Return the logarithm of the Gamma function of x.
18 * Method: call __ieee754_lgamma_r
21 #include "fdlibm.h"
22 #include <reent.h>
23 #include <errno.h>
25 #ifndef _DOUBLE_IS_32BITS
27 #ifdef __STDC__
28 double lgamma(double x)
29 #else
30 double lgamma(x)
31 double x;
32 #endif
34 #ifdef _IEEE_LIBM
35 return __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT)));
36 #else
37 double y;
38 struct exception exc;
39 y = __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT)));
40 if(_LIB_VERSION == _IEEE_) return y;
41 if(!finite(y)&&finite(x)) {
42 #ifndef HUGE_VAL
43 #define HUGE_VAL inf
44 double inf = 0.0;
46 SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
47 #endif
48 exc.name = "lgamma";
49 exc.err = 0;
50 exc.arg1 = x;
51 exc.arg2 = x;
52 if (_LIB_VERSION == _SVID_)
53 exc.retval = HUGE;
54 else
55 exc.retval = HUGE_VAL;
56 if(floor(x)==x&&x<=0.0) {
57 /* lgamma(-integer) */
58 exc.type = SING;
59 if (_LIB_VERSION == _POSIX_)
60 errno = EDOM;
61 else if (!matherr(&exc)) {
62 errno = EDOM;
65 } else {
66 /* lgamma(finite) overflow */
67 exc.type = OVERFLOW;
68 if (_LIB_VERSION == _POSIX_)
69 errno = ERANGE;
70 else if (!matherr(&exc)) {
71 errno = ERANGE;
74 if (exc.err != 0)
75 errno = exc.err;
76 return exc.retval;
77 } else
78 return y;
79 #endif
82 #endif /* defined(_DOUBLE_IS_32BITS) */