OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libm/] [math/] [w_gamma.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
 
2
/* @(#)w_gamma.c 5.1 93/09/24 */
3
/*
4
 * ====================================================
5
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6
 *
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
 * ====================================================
12
 *
13
 */
14
 
15
/*
16
FUNCTION
17
        <<gamma>>, <<gammaf>>, <<lgamma>>, <<lgammaf>>, <<gamma_r>>,
18
        <<gammaf_r>>, <<lgamma_r>>, <<lgammaf_r>>---logarithmic gamma
19
        function
20
INDEX
21
gamma
22
INDEX
23
gammaf
24
INDEX
25
lgamma
26
INDEX
27
lgammaf
28
INDEX
29
gamma_r
30
INDEX
31
gammaf_r
32
INDEX
33
lgamma_r
34
INDEX
35
lgammaf_r
36
 
37
ANSI_SYNOPSIS
38
#include <math.h>
39
double gamma(double <[x]>);
40
float gammaf(float <[x]>);
41
double lgamma(double <[x]>);
42
float lgammaf(float <[x]>);
43
double gamma_r(double <[x]>, int *<[signgamp]>);
44
float gammaf_r(float <[x]>, int *<[signgamp]>);
45
double lgamma_r(double <[x]>, int *<[signgamp]>);
46
float lgammaf_r(float <[x]>, int *<[signgamp]>);
47
 
48
TRAD_SYNOPSIS
49
#include <math.h>
50
double gamma(<[x]>)
51
double <[x]>;
52
float gammaf(<[x]>)
53
float <[x]>;
54
double lgamma(<[x]>)
55
double <[x]>;
56
float lgammaf(<[x]>)
57
float <[x]>;
58
double gamma_r(<[x]>, <[signgamp]>)
59
double <[x]>;
60
int <[signgamp]>;
61
float gammaf_r(<[x]>, <[signgamp]>)
62
float <[x]>;
63
int <[signgamp]>;
64
double lgamma_r(<[x]>, <[signgamp]>)
65
double <[x]>;
66
int <[signgamp]>;
67
float lgammaf_r(<[x]>, <[signgamp]>)
68
float <[x]>;
69
int <[signgamp]>;
70
 
71
DESCRIPTION
72
<<gamma>> calculates
73
@tex
74
$\mit ln\bigl(\Gamma(x)\bigr)$,
75
@end tex
76
the natural logarithm of the gamma function of <[x]>.  The gamma function
77
(<<exp(gamma(<[x]>))>>) is a generalization of factorial, and retains
78
the property that
79
@ifnottex
80
<<exp(gamma(N))>> is equivalent to <<N*exp(gamma(N-1))>>.
81
@end ifnottex
82
@tex
83
$\mit \Gamma(N)\equiv N\times\Gamma(N-1)$.
84
@end tex
85
Accordingly, the results of the gamma function itself grow very
86
quickly.  <<gamma>> is defined as
87
@tex
88
$\mit ln\bigl(\Gamma(x)\bigr)$ rather than simply $\mit \Gamma(x)$
89
@end tex
90
@ifnottex
91
the natural log of the gamma function, rather than the gamma function
92
itself,
93
@end ifnottex
94
to extend the useful range of results representable.
95
 
96
The sign of the result is returned in the global variable <<signgam>>,
97
which is declared in math.h.
98
 
99
<<gammaf>> performs the same calculation as <<gamma>>, but uses and
100
returns <<float>> values.
101
 
102
<<lgamma>> and <<lgammaf>> are alternate names for <<gamma>> and
103
<<gammaf>>.  The use of <<lgamma>> instead of <<gamma>> is a reminder
104
that these functions compute the log of the gamma function, rather
105
than the gamma function itself.
106
 
107
The functions <<gamma_r>>, <<gammaf_r>>, <<lgamma_r>>, and
108
<<lgammaf_r>> are just like <<gamma>>, <<gammaf>>, <<lgamma>>, and
109
<<lgammaf>>, respectively, but take an additional argument.  This
110
additional argument is a pointer to an integer.  This additional
111
argument is used to return the sign of the result, and the global
112
variable <<signgam>> is not used.  These functions may be used for
113
reentrant calls (but they will still set the global variable <<errno>>
114
if an error occurs).
115
 
116
RETURNS
117
Normally, the computed result is returned.
118
 
119
When <[x]> is a nonpositive integer, <<gamma>> returns <<HUGE_VAL>>
120
and <<errno>> is set to <<EDOM>>.  If the result overflows, <<gamma>>
121
returns <<HUGE_VAL>> and <<errno>> is set to <<ERANGE>>.
122
 
123
You can modify this error treatment using <<matherr>>.
124
 
125
PORTABILITY
126
Neither <<gamma>> nor <<gammaf>> is ANSI C.  */
127
 
128
/* double gamma(double x)
129
 * Return the logarithm of the Gamma function of x.
130
 *
131
 * Method: call gamma_r
132
 */
133
 
134
#include "fdlibm.h"
135
#include <reent.h>
136
#include <errno.h>
137
 
138
#ifndef _DOUBLE_IS_32BITS
139
 
140
#ifdef __STDC__
141
        double gamma(double x)
142
#else
143
        double gamma(x)
144
        double x;
145
#endif
146
{
147
#ifdef _IEEE_LIBM
148
        return __ieee754_gamma_r(x,&(_REENT_SIGNGAM(_REENT)));
149
#else
150
        double y;
151
        struct exception exc;
152
        y = __ieee754_gamma_r(x,&(_REENT_SIGNGAM(_REENT)));
153
        if(_LIB_VERSION == _IEEE_) return y;
154
        if(!finite(y)&&finite(x)) {
155
#ifndef HUGE_VAL 
156
#define HUGE_VAL inf
157
            double inf = 0.0;
158
 
159
            SET_HIGH_WORD(inf,0x7ff00000);      /* set inf to infinite */
160
#endif
161
            exc.name = "gamma";
162
            exc.err = 0;
163
            exc.arg1 = exc.arg2 = x;
164
            if (_LIB_VERSION == _SVID_)
165
                exc.retval = HUGE;
166
            else
167
                exc.retval = HUGE_VAL;
168
            if(floor(x)==x&&x<=0.0) {
169
                /* gamma(-integer) or gamma(0) */
170
                exc.type = SING;
171
                if (_LIB_VERSION == _POSIX_)
172
                  errno = EDOM;
173
                else if (!matherr(&exc)) {
174
                  errno = EDOM;
175
                }
176
            } else {
177
                /* gamma(finite) overflow */
178
                exc.type = OVERFLOW;
179
                if (_LIB_VERSION == _POSIX_)
180
                  errno = ERANGE;
181
                else if (!matherr(&exc)) {
182
                  errno = ERANGE;
183
                }
184
            }
185
            if (exc.err != 0)
186
               errno = exc.err;
187
            return exc.retval;
188
        } else
189
            return y;
190
#endif
191
}
192
 
193
#endif /* defined(_DOUBLE_IS_32BITS) */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.