Skip to content

Commit de9b1f8

Browse files
authored
Merge pull request #876 from cyrilgandon/fix-doubling-precision
fix(factorial): result should be of the default kind, not double default kind
2 parents 2db51d1 + 6d8076f commit de9b1f8

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/stdlib_specialfunctions_gamma.fypp

+5-5
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,9 @@ contains
528528
! Log(n!)
529529
!
530530
${t1}$, intent(in) :: n
531-
real :: res
531+
real(dp) :: res
532532
${t1}$, parameter :: zero = 0_${k1}$, one = 1_${k1}$, two = 2_${k1}$
533-
real, parameter :: zero_k2 = 0.0
533+
real(dp), parameter :: zero_dp = 0.0_dp
534534

535535
if(n < zero) call error_stop("Error(l_factorial): Logarithm of" &
536536
//" factorial function argument must be non-negative")
@@ -539,15 +539,15 @@ contains
539539

540540
case (zero)
541541

542-
res = zero_k2
542+
res = zero_dp
543543

544544
case (one)
545545

546-
res = zero_k2
546+
res = zero_dp
547547

548548
case (two : )
549549

550-
res = l_gamma(n + 1, 1.0D0)
550+
res = l_gamma(n + 1, 1.0_dp)
551551

552552
end select
553553
end function l_factorial_${t1[0]}$${k1}$

test/specialfunctions/test_specialfunctions_gamma.fypp

+9-12
Original file line numberDiff line numberDiff line change
@@ -89,36 +89,33 @@ contains
8989

9090
${t1}$, parameter :: x(n) = [0_${k1}$, 1_${k1}$, 2_${k1}$, 4_${k1}$, &
9191
5_${k1}$, 100_${k1}$]
92-
real(sp), parameter :: ans(n) = [0.0, 0.0, 0.693147180, 3.17805383, &
93-
4.78749174, 3.63739376e2]
92+
real(dp), parameter :: ans(n) = [0.0_dp, 0.0_dp, 0.69314718055994_dp, 3.17805383034794_dp, &
93+
4.78749174278204_dp, 3.637393755555e2_dp]
9494

9595
#:elif k1 == "int16"
9696

9797
${t1}$, parameter :: x(n) = [0_${k1}$, 1_${k1}$, 2_${k1}$, 4_${k1}$, &
9898
7_${k1}$, 500_${k1}$]
99-
real(sp), parameter :: ans(n) = [0.0, 0.0, 0.693147180, 3.17805383, &
100-
8.52516136, 2.61133046e3]
101-
99+
real(dp), parameter :: ans(n) = [0.0_dp, 0.0_dp, 0.69314718055994_dp, 3.17805383034794_dp, &
100+
8.52516136106541_dp, 2.611330458460e3_dp]
102101
#:elif k1 == "int32"
103102

104103
${t1}$, parameter :: x(n) = [0_${k1}$, 1_${k1}$, 2_${k1}$, 4_${k1}$, &
105104
12_${k1}$, 7000_${k1}$]
106-
real(sp), parameter :: ans(n) = [0.0, 0.0, 0.693147180, 3.17805383, &
107-
1.99872145e1, 5.49810038e4]
108-
105+
real(dp), parameter :: ans(n) = [0.0_dp, 0.0_dp, 0.69314718055994_dp, 3.17805383034794_dp, &
106+
1.998721449566e1_dp, 5.498100377941e4_dp]
109107
#:elif k1 == "int64"
110108

111109
${t1}$, parameter :: x(n) = [0_${k1}$, 1_${k1}$, 2_${k1}$, 4_${k1}$, &
112110
20_${k1}$, 90000_${k1}$]
113-
real(sp), parameter :: ans(n) = [0.0, 0.0, 0.693147180, 3.17805383, &
114-
4.23356165e1, 9.36687468e5]
115-
111+
real(dp), parameter :: ans(n) = [0.0_dp, 0.0_dp, 0.69314718055994_dp, 3.17805383034794_dp, &
112+
4.233561646075e1_dp, 9.366874681600e5_dp]
116113
#:endif
117114

118115
do i = 1, n
119116

120117
call check(error, log_factorial(x(i)), ans(i), "Integer kind " &
121-
//"${k1}$ failed", thr = tol_sp, rel = .true.)
118+
//"${k1}$ failed", thr = tol_dp, rel = .true.)
122119

123120
end do
124121
end subroutine test_logfact_${t1[0]}$${k1}$

0 commit comments

Comments
 (0)