From 7ee6cf74237eab4b64a8a1d032b72044a940e9c9 Mon Sep 17 00:00:00 2001 From: Helen Kershaw Date: Fri, 15 Dec 2023 12:41:45 -0500 Subject: [PATCH 1/2] changing from real to real64 to try and improve result still giving incorrect value for pi --- Fortran/exercise1/calc_pi.f90 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Fortran/exercise1/calc_pi.f90 b/Fortran/exercise1/calc_pi.f90 index 1833099..426d210 100644 --- a/Fortran/exercise1/calc_pi.f90 +++ b/Fortran/exercise1/calc_pi.f90 @@ -1,10 +1,11 @@ program calc_pi +use iso_fortran_env implicit none integer, parameter :: num_samples = 1000000 ! Number of random samples -real :: x, y -real :: pi_approx +real(real64) :: x, y +real(real64) :: pi_approx integer :: i, count_inside_circle count_inside_circle = 0 From dc40043d2fb46112e157f6c921fb694bcbb9af1c Mon Sep 17 00:00:00 2001 From: Helen Kershaw Date: Fri, 15 Dec 2023 12:43:34 -0500 Subject: [PATCH 2/2] bug-fix: was using x twice rather than x and y to check for point in circle --- Fortran/exercise1/calc_pi.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Fortran/exercise1/calc_pi.f90 b/Fortran/exercise1/calc_pi.f90 index 426d210..022c386 100644 --- a/Fortran/exercise1/calc_pi.f90 +++ b/Fortran/exercise1/calc_pi.f90 @@ -15,7 +15,7 @@ program calc_pi call random_number(x) call random_number(y) - if (x**2 + x**2 <= 1.0) then + if (x**2 + y**2 <= 1.0) then count_inside_circle = count_inside_circle + 1 end if end do