DoubleFactorial.f90 557 Bytes
Newer Older
1 2 3 4 5 6 7 8
module m_DoubleFactorial

implicit none


contains

  
9
real function DoubleFactorial( n_upper, n_lower )
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
! calculates ( 2 * n_upper + 1 ) !! / ( 2 * n_lower + 1 ) !! or just ( 2 * n_upper + 1 ) !!, if n_lower is not present

  integer           :: n_upper
  integer, optional :: n_lower
  integer           :: i, i_lower

  i_lower = 1
  if( present(n_lower) ) i_lower = n_lower + 1

  DoubleFactorial = 1.
  do i = i_lower, n_upper
    DoubleFactorial = DoubleFactorial * ( 2 * i + 1 )
  end do

end function DoubleFactorial


end module m_DoubleFactorial