Skip to content

Commit

Permalink
Merge pull request lfortran#4478 from parth121101/test_15
Browse files Browse the repository at this point in the history
tests: add tests for `log_gamma` and `dgamma` intrinsic
  • Loading branch information
parth121101 authored Jul 18, 2024
2 parents c2cea9e + 77e3186 commit 8995adf
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
4 changes: 3 additions & 1 deletion integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,10 @@ RUN(NAME intrinsics_286 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # atanh
RUN(NAME intrinsics_288 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) # spread
RUN(NAME intrinsics_289 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # ishftc
RUN(NAME intrinsics_290 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # log10
RUN(NAME intrinsics_291 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # log10
RUN(NAME intrinsics_291 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # gamma
RUN(NAME intrinsics_292 LABELS gfortran llvm) # command_argument_count
RUN(NAME intrinsics_293 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # dgamma
RUN(NAME intrinsics_294 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc) # log_gamma

RUN(NAME passing_array_01 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc)
RUN(NAME passing_array_02 LABELS gfortran fortran llvm llvm_wasm llvm_wasm_emcc)
Expand Down
39 changes: 39 additions & 0 deletions integration_tests/intrinsics_293.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
program intrinsics_293
use, intrinsic :: iso_fortran_env, only: dp => real64
real(dp) :: a
integer :: i
real(dp) :: dgamma_runtime_dp(3) = [0.875_dp, 3.367_dp, 2.140_dp]
real(dp) :: dgamma_res_dp(3)
real(dp) :: expected_dp(3) = [1.0896523574228969_dp, 2.8783551043979587_dp, 1.0675143148681314_dp]

real(dp), parameter :: res(3) = dgamma([0.875_dp, 3.367_dp, 2.140_dp])

do i = 1, 3
print *, res(i)
if (abs(res(i) - expected_dp(i)) > 1e-12_dp) error stop
end do

dgamma_res_dp = dgamma(dgamma_runtime_dp)

do i = 1, 3
print *, dgamma_res_dp(i)
if (abs(dgamma_res_dp(i) - expected_dp(i)) > 1e-12_dp) error stop
end do

a = dgamma(10.92839272_dp)

print *, a
if (a - 3067135.1568285478_dp > 1e-12_dp) error stop

print *,dgamma(10.92839272_dp)
if (dgamma(10.92839272_dp) - 3067135.1568285478_dp > 1e-12_dp) error stop

a = dgamma(83.728927_dp)

print *, a
! if (abs(a - 1.1895370148607565E+124_dp) > 1e-12_dp) error stop

print *,dgamma(83.728927_dp)
! if (abs(dgamma(83.728927_dp) - 1.1895370148607565E+124_dp) > 1e-12_dp) error stop

end program
69 changes: 69 additions & 0 deletions integration_tests/intrinsics_294.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
program intrinsics_294
use, intrinsic :: iso_fortran_env, only: dp => real64, sp => real32
real(dp) :: a
real(sp) :: d
integer :: i
real(dp) :: log_gamma_runtime_dp(3) = [0.875_dp, 3.367_dp, 2.140_dp]
real(sp) :: log_gamma_runtime_sp(3) = [0.875, 3.367, 2.140]
real(dp) :: log_gamma_res_dp(3)
real(sp) :: log_gamma_res_sp(3)
real(dp) :: expected_dp(3) = [8.5858707225334327E-002_dp, 1.0572189866765507_dp, 6.5332875743268432E-002_dp]
real(sp) :: expected_sp(3) = [8.58587101E-02_sp, 1.05721915_sp, 6.53329268E-02]

real(dp), parameter :: res(3) = log_gamma([0.875_dp, 3.367_dp, 2.140_dp])
real(sp), parameter :: res_sp(3) = log_gamma([0.875, 3.367, 2.140])

do i = 1, 3
print *, res(i)
if (abs(res(i) - expected_dp(i)) > 1e-12_dp) error stop
end do

do i = 1, 3
print *, res_sp(i)
if (abs(res_sp(i) - expected_sp(i)) > 1e-5) error stop
end do

log_gamma_res_dp = log_gamma(log_gamma_runtime_dp)
log_gamma_res_sp = log_gamma(log_gamma_runtime_sp)

do i = 1, 3
print *, log_gamma_res_dp(i)
if (abs(log_gamma_res_dp(i) - expected_dp(i)) > 1e-12_dp) error stop
end do

do i = 1, 3
print *, log_gamma_res_sp(i)
if (abs(log_gamma_res_sp(i) - expected_sp(i)) > 1e-5) error stop
end do

a = log_gamma(10.92839272_dp)
d = log_gamma(10.92839272)

print *, a
if (a - 14.936254510214283_dp > 1e-12_dp) error stop

print *,log_gamma(10.92839272_dp)
if (log_gamma(10.92839272_dp) - 14.936254510214283_dp > 1e-12_dp) error stop

print *, d
if (d - 14.9362535_sp > 1e-5) error stop

print *, log_gamma(10.92839272)
if (log_gamma(10.92839272) - 14.9362535_sp > 1e-5) error stop

a = log_gamma(83.728927_dp)
d = log_gamma(31.738222)

print *, a
if (a - 285.69411569953820_dp > 1e-12_dp) error stop

print *,log_gamma(83.728927_dp)
if (log_gamma(83.728927_dp) - 285.69411569953820_dp > 1e-12_dp) error stop

print *, d
if (d - 77.1901703_sp > 1e-5) error stop

print *, log_gamma(31.738222)
if (log_gamma(31.738222) - 77.1901703_sp > 1e-5) error stop

end program

0 comments on commit 8995adf

Please sign in to comment.