diff --git a/INSTALL.txt b/INSTALL.txt index 9a1ab6e..95f1a34 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -1,4 +1,6 @@ * define $QUACK_ROOT +* blas +* lapack * ninja * gfortran * python3 @@ -6,4 +8,5 @@ * opam * cmake * wget +* automake diff --git a/src/utils/dfac.f90 b/src/utils/dfac.f90 new file mode 100644 index 0000000..b58a2a6 --- /dev/null +++ b/src/utils/dfac.f90 @@ -0,0 +1,66 @@ +double precision function dfac(n) + implicit none + integer :: n + double precision, external :: fact + dfac = fact(n) +end + +!------------------- +! The following functions were taken with from Quantum Package +! (https://github.com/QuantumPackage/qp2 , AGPL license) + +double precision function fact(n) + implicit none + integer :: n + double precision, save :: memo(1:100) + integer, save :: memomax = 1 + integer :: i + double precision :: logfact + + if (n<=memomax) then + if (n<2) then + fact = 1.d0 + else + fact = memo(n) + endif + return + endif + + memo(1) = 1.d0 + do i=memomax+1,min(n,100) + memo(i) = memo(i-1)*dble(i) + enddo + memomax = min(n,100) + fact = dexp(logfact(n)) +end function + + + +double precision function logfact(n) + implicit none + integer :: n + double precision, save :: memo(1:100) + integer, save :: memomax = 1 + integer :: i + + if (n<=memomax) then + if (n<2) then + logfact = 0.d0 + else + logfact = memo(n) + endif + return + endif + + memo(1) = 0.d0 + do i=memomax+1,min(n,100) + memo(i) = memo(i-1)+dlog(dble(i)) + enddo + memomax = min(n,100) + logfact = memo(memomax) + do i=101,n + logfact = logfact + dlog(dble(i)) + enddo +end function + +