[user@openwork fortran]$ cat test.f90 module m_test implicit none integer, parameter :: dp = selected_real_kind(15, 307) contains ! calculate pi using Gregory-Leibniz algorithm ! https://craftofcoding.wordpress.com/2020/04/09/calculating-π-with-gregory-leibniz-ii-fortran/ function pi_leibniz(n) result(x) bind(c, name = 'pi_leibniz') integer, value :: n integer :: i real (kind=dp) :: x x = 1.0_dp do i = 1,n if (mod(i,2) == 1) then x = x - (1.0_dp / ((i*2.0_dp)+1.0_dp)) else x = x + (1.0_dp / ((i*2.0_dp)+1.0_dp)) end if end do x = x * 4.0_dp end function pi_leibniz end module m_test
https://misskey-taube.s3.wasabisys.com/files/44e0f11e-183a-4b89-a8c1-fd5d1c0f940f.png