| 1 |
# gamma(x): Gamma |
| 2 |
|
| 3 |
Gamma function. |
| 4 |
|
| 5 |
## Declaration |
| 6 |
|
| 7 |
### Syntax |
| 8 |
|
| 9 |
```fortran |
| 10 |
retval = gamma(x) |
| 11 |
elemental real function gamma(x) |
| 12 |
``` |
| 13 |
|
| 14 |
### Arguments |
| 15 |
|
| 16 |
`x` the input value must be of type real. It should not be zero or a negative |
| 17 |
integer. |
| 18 |
|
| 19 |
### Return values |
| 20 |
|
| 21 |
The return value is of same type and kind as of `x`. |
| 22 |
|
| 23 |
## Description |
| 24 |
|
| 25 |
**gamma(x)** computes $\gamma(x)$. For positive, integer value of `x`, the Gamma |
| 26 |
function simplifies to factorial function: |
| 27 |
|
| 28 |
$\gamma(x) = (x-1)!$ |
| 29 |
|
| 30 |
In general, if $x > 0$: |
| 31 |
|
| 32 |
$\gamma(x) = \int_{0}^{\infty} e^{-t} dt$ |
| 33 |
|
| 34 |
and if $-n-1 < x < -n$ where n is an integer >= 0: |
| 35 |
|
| 36 |
$\gamma(x) = \int_{0}^{\infty}(e ^{-t} - \sum\limits_{k=0}^n \frac{(-t)^k}{k!} dt)$ |
| 37 |
|
| 38 |
## Types |
| 39 |
|
| 40 |
Supported argument types is real. |
| 41 |
|
| 42 |
```fortran |
| 43 |
interface gamma |
| 44 |
module procedure sgamma, dgamma |
| 45 |
end interface |
| 46 |
|
| 47 |
contains |
| 48 |
|
| 49 |
elemental real(sp) function sgamma(x) |
| 50 |
real(sp), intent(in) :: x |
| 51 |
end function |
| 52 |
|
| 53 |
elemental real(dp) function dgamma(x) |
| 54 |
real(dp), intent(in) :: x |
| 55 |
end function |
| 56 |
``` |
| 57 |
|
| 58 |
## Examples |
| 59 |
|
| 60 |
```fortran |
| 61 |
program intrinsics_gamma |
| 62 |
print *, gamma(0.5) |
| 63 |
print *, gamma(1.0) |
| 64 |
end program |
| 65 |
``` |
| 66 |
|
| 67 |
**Result:** |
| 68 |
|
| 69 |
``` |
| 70 |
1.77245 |
| 71 |
1.000 |
| 72 |
``` |
| 73 |
|
| 74 |
## See Also |
| 75 |
|
| 76 |
[epsilon](epsilon.md) |