You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since factorials often arise in calculations, I suggest adding to stdlib_constants a named array constant factorial(1:20) of type int64 containing the factorials of 1 through 20, since that is what int64 can hold. Similar named constants such as double_factorial could also be added. An alternative to defining a single named constant factorial would be to define named array constants factorial_int8, factorial_int16, factorial_int32, factorial_int64. factorial_real32, factorial_real64, factorial_real128 holding the factorials that fit into the corresponding data types. The advantages of making factorial a named constant instead of a function is speed and avoiding overflow. Named constants for the absolute moments of the normal distribution (which involve double factorials) are useful to me, but maybe this is too specialized for stdlib.
The code
program xfactorial
use iso_fortran_env, only: int64
implicit none
integer, parameter :: dp = kind(1.0d0), ikind=int64
integer(kind=int64) :: i, fac
real(kind=dp) :: x
fac = 1_ikind
x = 1.0_dp
print*,huge(i)
do i=2,21
fac = fac*i
x = x*i
print*,i,fac,x,fac/x
end do
end program xfactorial
Since factorials often arise in calculations, I suggest adding to
stdlib_constants
a named array constantfactorial(1:20)
of typeint64
containing the factorials of 1 through 20, since that is whatint64
can hold. Similar named constants such as double_factorial could also be added. An alternative to defining a single named constantfactorial
would be to define named array constantsfactorial_int8
,factorial_int16
,factorial_int32
,factorial_int64
.factorial_real32
,factorial_real64
,factorial_real128
holding the factorials that fit into the corresponding data types. The advantages of making factorial a named constant instead of a function is speed and avoiding overflow. Named constants for the absolute moments of the normal distribution (which involve double factorials) are useful to me, but maybe this is too specialized for stdlib.The code
gives
The text was updated successfully, but these errors were encountered: