Skip to content

Commit

Permalink
Merge pull request lfortran#4476 from parth121101/test_14
Browse files Browse the repository at this point in the history
tests: add tests for `gamma` and `log10` intrinsic
  • Loading branch information
certik authored Jul 11, 2024
2 parents 479c427 + 4e30526 commit 53e4287
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
2 changes: 2 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,8 @@ RUN(NAME intrinsics_285 LABELS gfortran llvm llvm_wasm llvm_wasm_emcc fortran) #
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 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
69 changes: 69 additions & 0 deletions integration_tests/intrinsics_290.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
program intrinsics_290
use, intrinsic :: iso_fortran_env, only: dp => real64, sp => real32
real(dp) :: a
real(sp) :: d
integer :: i
real(dp) :: log_runtime_dp(3) = [0.875_dp, 3.367_dp, 2.140_dp]
real(sp) :: log_runtime_sp(3) = [0.875, 3.367, 2.140]
real(dp) :: log_res_dp(3)
real(sp) :: log_res_sp(3)
real(dp) :: expected_dp(3) = [-5.7991946977686754E-002_dp, 0.52724311638808863_dp, 0.33041377334919086_dp]
real(sp) :: expected_sp(3) = [-5.79919480E-02_sp, 0.527243137_sp, 0.330413789]

real(dp), parameter :: res(3) = log10([0.875_dp, 3.367_dp, 2.140_dp])
real(sp), parameter :: res_sp(3) = log10([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_res_dp = log10(log_runtime_dp)
log_res_sp = log10(log_runtime_sp)

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

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

a = log10(10.92839272_dp)
d = log10(10.92839272)

print *, a
if (a - 1.03855629331626087e+00_dp > 1e-12_dp) error stop

print *,log10(10.92839272_dp)
if (log10(10.92839272_dp) - 1.03855629331626087e+00_dp > 1e-12_dp) error stop

print *, d
if (d - 1.03855634e+00_sp > 1e-5) error stop

print *, log10(10.92839272)
if (log10(10.92839272) - 1.03855634e+00_sp > 1e-5) error stop

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

print *, a
if (a - 1.92287552568858744e+00_dp > 1e-12_dp) error stop

print *,log10(83.728927_dp)
if (log10(83.728927_dp) - 1.92287552568858744e+00_dp > 1e-12_dp) error stop

print *, d
if (d - 1.50158262e+00_sp > 1e-5) error stop

print *, log10(31.738222)
if (log10(31.738222) - 1.50158262e+00_sp > 1e-5) error stop

end program
69 changes: 69 additions & 0 deletions integration_tests/intrinsics_291.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
program intrinsics_291
use, intrinsic :: iso_fortran_env, only: dp => real64, sp => real32
real(dp) :: a
real(sp) :: d
integer :: i
real(dp) :: log_runtime_dp(3) = [0.73925_dp, 4.6272183_dp, 82.1483927190_dp]
real(sp) :: log_runtime_sp(3) = [0.73925, 4.6272183, 8.14839]
real(dp) :: log_res_dp(3)
real(sp) :: log_res_sp(3)
real(dp) :: expected_dp(3) = [1.2399882923281214_dp, 13.907361652217805_dp, 1.1139704077610786E+121_dp]
real(sp) :: expected_sp(3) = [1.23998833, 13.9073610, 6807.07861]

real(dp), parameter :: res(3) = gamma([0.73925_dp, 4.6272183_dp, 82.1483927190_dp])
real(sp), parameter :: res_sp(3) = gamma([0.73925, 4.6272183_sp, 8.14839])

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_res_dp = gamma(log_runtime_dp)
log_res_sp = gamma(log_runtime_sp)

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

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

a = gamma(21.7282828_dp)
d = gamma(11.63827)

print *, a
if (a - 2.22349180143608259e+19_dp > 1e-12_dp) error stop

print *,gamma(21.7282828_dp)
if (gamma(21.7282828_dp) - 2.22349180143608259e+19_dp > 1e-12_dp) error stop

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

print *, gamma(11.63827)
if (gamma(11.63827) - 16592656.0_sp > 1e-5) error stop

a = gamma(61.72812_dp)
d = gamma(7.72818)

print *, a
if (a - 1.65731626595094650e+83_dp > 1e-12_dp) error stop

print *,gamma(61.72812_dp)
if (gamma(61.72812_dp) - 1.65731626595094650e+83_dp > 1e-12_dp) error stop

print *, d
if (d - 2.92850854e+03_sp > 1e-5) error stop

print *, gamma(7.72818)
if (gamma(7.72818) - 2.92850854e+03_sp > 1e-5) error stop

end program

0 comments on commit 53e4287

Please sign in to comment.