主题:求助解释几行程序
real FUNCTION gamma(xx)
! Modified from "Numerical Recipes"
IMPLICIT NONE
! PASSING PARAMETERS:
real, intent(IN) :: xx
! LOCAL PARAMETERS:
integer :: j
real*8 :: ser,stp,tmp,x,y,cof(6),gammadp
SAVE cof,stp
DATA cof,stp/76.18009172947146d0,-86.50532032941677d0, &
24.01409824083091d0,-1.231739572450155d0,.1208650973866179d-2, &
-.5395239384953d-5,2.5066282746310005d0/
x=dble(xx)
y=x
tmp=x+5.5d0
tmp=(x+0.5d0)*log(tmp)-tmp
ser=1.000000000190015d0
! do j=1,6 !original
do j=1,4
!!do j=1,3 !gives result to within ~ 3 %
y=y+1.d0
ser=ser+cof(j)/y
enddo
gammadp=tmp+log(stp*ser/x)
gammadp= exp(gammadp)
[b][color=0000FF]#if (DWORDSIZE == 8 && RWORDSIZE == 8)
gamma = gammadp
#elif (DWORDSIZE == 8 && RWORDSIZE == 4)
gamma = sngl(gammadp)
#else
This is a temporary hack assuming double precision is 8 bytes.
#endif[/color][/b] END FUNCTION gamma
! Modified from "Numerical Recipes"
IMPLICIT NONE
! PASSING PARAMETERS:
real, intent(IN) :: xx
! LOCAL PARAMETERS:
integer :: j
real*8 :: ser,stp,tmp,x,y,cof(6),gammadp
SAVE cof,stp
DATA cof,stp/76.18009172947146d0,-86.50532032941677d0, &
24.01409824083091d0,-1.231739572450155d0,.1208650973866179d-2, &
-.5395239384953d-5,2.5066282746310005d0/
x=dble(xx)
y=x
tmp=x+5.5d0
tmp=(x+0.5d0)*log(tmp)-tmp
ser=1.000000000190015d0
! do j=1,6 !original
do j=1,4
!!do j=1,3 !gives result to within ~ 3 %
y=y+1.d0
ser=ser+cof(j)/y
enddo
gammadp=tmp+log(stp*ser/x)
gammadp= exp(gammadp)
[b][color=0000FF]#if (DWORDSIZE == 8 && RWORDSIZE == 8)
gamma = gammadp
#elif (DWORDSIZE == 8 && RWORDSIZE == 4)
gamma = sngl(gammadp)
#else
This is a temporary hack assuming double precision is 8 bytes.
#endif[/color][/b] END FUNCTION gamma