Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
 
2
/*
3
 * ====================================================
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * Developed at SunPro, a Sun Microsystems, Inc. business.
7
 * Permission to use, copy, modify, and distribute this
8
 * software is freely granted, provided that this notice
9
 * is preserved.
10
 * ====================================================
11
 *
12
 */
13
14
 
15
 * Return the logarithm of the Gamma function of x.
16
 *
17
 * Method: call __ieee754_lgamma_r
18
 */
19
20
 
21
#include 
22
#include 
23
24
 
25
26
 
27
	double lgamma(double x)
28
#else
29
	double lgamma(x)
30
	double x;
31
#endif
32
{
33
#ifdef _IEEE_LIBM
34
	return __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT)));
35
#else
36
        double y;
37
	struct exception exc;
38
        y = __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT)));
39
        if(_LIB_VERSION == _IEEE_) return y;
40
        if(!finite(y)&&finite(x)) {
41
#ifndef HUGE_VAL
42
#define HUGE_VAL inf
43
	    double inf = 0.0;
44
45
 
46
#endif
47
	    exc.name = "lgamma";
48
	    exc.err = 0;
49
	    exc.arg1 = x;
50
	    exc.arg2 = x;
51
            if (_LIB_VERSION == _SVID_)
52
               exc.retval = HUGE;
53
            else
54
               exc.retval = HUGE_VAL;
55
	    if(floor(x)==x&&x<=0.0) {
56
		/* lgamma(-integer) */
57
		exc.type = SING;
58
		if (_LIB_VERSION == _POSIX_)
59
		   errno = EDOM;
60
		else if (!matherr(&exc)) {
61
		   errno = EDOM;
62
		}
63
64
 
65
		/* lgamma(finite) overflow */
66
		exc.type = OVERFLOW;
67
                if (_LIB_VERSION == _POSIX_)
68
		   errno = ERANGE;
69
                else if (!matherr(&exc)) {
70
                   errno = ERANGE;
71
		}
72
            }
73
	    if (exc.err != 0)
74
	       errno = exc.err;
75
            return exc.retval;
76
        } else
77
            return y;
78
#endif
79
}
80
81
 
82