Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The missing factorial function #19

Closed
urbanjost opened this issue Dec 24, 2021 · 1 comment
Closed

The missing factorial function #19

urbanjost opened this issue Dec 24, 2021 · 1 comment

Comments

@urbanjost
Copy link

Why does Fortran not have a factorial function?

It does, as for positive whole values of X the Gamma
function simplifies to the factorial function for (X-1).
That is,

x! == gamma(x+1)
program testit
use, intrinsic :: iso_fortran_env, only : wp=>real64
integer,parameter :: n(*)=[0,1,5,11,170]
integer :: j

   do j=1,size(n)
      write(*,'(*(g0,1x))')'factorial of', n(j),' is ', &
       & product([(real(i,kind=wp),i=1,n(j))]),         &
       & ' or ',                                        &
       & gamma(real(n(j)+1,kind=wp))
   enddo

end program testit
@Beliavsky
Copy link
Owner

Posted, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants