File size: 7,007 Bytes
803451e
 
1
2
3
{"text": "INTEGER FUNCTION euclid_sub(a, b)\n    IMPLICIT NONE\n    INTEGER, INTENT(INOUT) :: a, b\n\n\n    a = ABS(a)\n    b = ABS(b)\n\n    DO WHILE (a /= b)\n    \n        IF (a > b) THEN\n            a = a - b\n        ELSE\n            b = b - a\n        END IF\n    END DO\n\n    euclid_sub = a\nEND FUNCTION euclid_sub \n\nINTEGER FUNCTION euclid_mod(a, b)\n    IMPLICIT NONE\n    INTEGER, INTENT(INOUT) :: a, b\n    INTEGER             :: temp\n\n\n    DO WHILE (b > 0)\n        temp = b\n        b = MODULO(a,b)\n        a = temp\n    END DO\n\n    euclid_mod = a\n\nEND FUNCTION euclid_mod\n\nPROGRAM euclidean\n    \n    IMPLICIT NONE\n    INTEGER :: a, b, euclid_sub, euclid_mod, temp_a, temp_b, ioerror\n    \n    DO\n        WRITE(*,*) 'Calculate greatest common divisor. Give two integers:'\n        READ(*, '(i10)', iostat=ioerror) temp_a, temp_b\n        \n        IF (ioerror == 0) THEN\n            EXIT\n        END IF\n    \n        WRITE(*,*) 'Entered numbers are not integers. Try again.'\n    END DO\n    \n    a = temp_a\n    b = temp_b\n    WRITE(*,*) 'Subtraction method: GCD is: ', euclid_sub(a, b)\n    \n    a = temp_a \n    b = temp_b \n    WRITE(*,*) 'Modulus method:     GCD is: ', euclid_mod(a, b)\nEND PROGRAM euclidean \n", "meta": {"hexsha": "5efae952f4556423ded2121d4999805017480e23", "size": 1187, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "contents/euclidean_algorithm/code/fortran/interactive_euclidean.f90", "max_stars_repo_name": "atocil/algorithm-archive", "max_stars_repo_head_hexsha": "2eb30cb103508c9efb91621564bd3114eb49d3af", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 1975, "max_stars_repo_stars_event_min_datetime": "2018-04-28T13:46:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T13:14:47.000Z", "max_issues_repo_path": "contents/euclidean_algorithm/code/fortran/interactive_euclidean.f90", "max_issues_repo_name": "atocil/algorithm-archive", "max_issues_repo_head_hexsha": "2eb30cb103508c9efb91621564bd3114eb49d3af", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 632, "max_issues_repo_issues_event_min_datetime": "2018-04-28T10:27:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-28T20:38:53.000Z", "max_forks_repo_path": "contents/euclidean_algorithm/code/fortran/interactive_euclidean.f90", "max_forks_repo_name": "atocil/algorithm-archive", "max_forks_repo_head_hexsha": "2eb30cb103508c9efb91621564bd3114eb49d3af", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 433, "max_forks_repo_forks_event_min_datetime": "2018-04-27T22:50:22.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-22T06:16:03.000Z", "avg_line_length": 19.4590163934, "max_line_length": 74, "alphanum_fraction": 0.5248525695, "num_tokens": 356, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9674102580527664, "lm_q2_score": 0.9324533097989077, "lm_q1q2_score": 0.9020648970547174}}
{"text": "! Program    : Exercise_16\n! Author     : FortranFan\n! Reference  : https://en.wikipedia.org/wiki/Gauss%27s_continued_fraction#cite_note-8\n!\n! Description:\n! An example implementation that illustrates how to employ a\n! RECURIVE function in Fortran to compute the tangent of x using\n! Lambert's continued fraction dating back to 1768 which gives\n! tan(x) = x/(1-x**2/(3-x**2/(5-x**2/(7-x**2/..))))\n!\n\nmodule kinds_m\n    ! Returns the kind value of a real data type with decimal precision of at least P digits\n    integer, parameter :: WP = selected_real_kind( p=12 ) ! Select suitable precision\nend module kinds_m\n\nmodule trig_m\n    ! importing WP from kinds module\n    use kinds_m, only: WP\n    ! Named constants\n    real(WP), parameter :: ONE = 1.0_wp\n    real(WP), parameter :: TWO = 2.0_wp\n    real(WP), parameter :: PI = 3.14159265358979323846264338327950288_wp\n    real(WP), parameter :: DEG_TO_RAD = PI/180.0_wp\n    real(WP), parameter :: TOL = 1e-3_wp !<-- Suitable tolerance for continued fraction series\n    real(WP), parameter :: UPPER_LIMIT = ONE/TOL\n\ncontains\n    elemental function tand(degx) result(tanx)\n      ! Calculate tangent of x in degrees using Lambert's formula\n      ! Argument list\n      real(WP), intent(in) :: degx ! x in degrees\n      ! Function result\n      real(WP) :: tanx\n      ! Local variables\n      real(WP) :: x\n      x = degx * DEG_TO_RAD\n      tanx = x / ( ONE + CalcFracLambert(x, n = 1))\n      return\n    end function tand\n\n    pure recursive function CalcFracLambert(x, n) result(Frac)\n      ! Argument list\n      real(WP), intent(in) :: x ! x in radians\n      integer, intent(in)  :: n\n      ! Function result\n      real(WP) :: Frac\n      ! Local variables\n      real(WP) :: Term\n      Term = TWO*n + ONE\n      if ( Term > UPPER_LIMIT ) then\n         Frac = - x**2 / Term\n      else\n         Frac = - x**2 / ( Term + CalcFracLambert(x, n+1) )\n      end if\n      return\n  end function CalcfracLambert\nend module trig_m\n\nprogram CalcTanx\n    ! importing relevant modules\n    use kinds_m, only: WP\n    use trig_m, only: tand, DEG_TO_RAD\n    ! declaring and initializing variables\n    real(WP) :: degx, tanx\n    degx = 40.0_wp\n    ! Calcuating tan value\n    tanx = tand(degx)\n    ! printing results\n    print *, \"x(degrees): \", degx\n    print *, \"tan(x) using Lambert's formula: \", tanx\n    print *, \"% diff with intrinsic tan: \", (tanx/tan(degx*DEG_TO_RAD)-1.0_wp)*100.0_wp\n    stop\nend program CalcTanx\n", "meta": {"hexsha": "c25e671f1692b77d331a7b9e549f7f7edb9a84ee", "size": 2443, "ext": "f90", "lang": "FORTRAN", "max_stars_repo_path": "src/numerical methods/Exercise_16.f90", "max_stars_repo_name": "EverLookNeverSee/FCS", "max_stars_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_stars_repo_licenses": ["MIT"], "max_stars_count": 2, "max_stars_repo_stars_event_min_datetime": "2020-04-14T10:30:25.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-17T13:03:15.000Z", "max_issues_repo_path": "src/numerical methods/Exercise_16.f90", "max_issues_repo_name": "EverLookNeverSee/FCS", "max_issues_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_issues_repo_licenses": ["MIT"], "max_issues_count": 3, "max_issues_repo_issues_event_min_datetime": "2020-06-06T13:54:45.000Z", "max_issues_repo_issues_event_max_datetime": "2020-07-25T20:32:23.000Z", "max_forks_repo_path": "src/numerical methods/Exercise_16.f90", "max_forks_repo_name": "EverLookNeverSee/FCS", "max_forks_repo_head_hexsha": "aa69d069d14e8dc20a9d176014c8a6a6b99322d4", "max_forks_repo_licenses": ["MIT"], "max_forks_count": 1, "max_forks_repo_forks_event_min_datetime": "2020-06-08T12:57:46.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-08T12:57:46.000Z", "avg_line_length": 32.5733333333, "max_line_length": 94, "alphanum_fraction": 0.6446991404, "num_tokens": 728, "lm_name": "Qwen/Qwen-72B", "lm_label": "1. YES\n2. YES", "lm_q1_score": 0.9715639677785087, "lm_q2_score": 0.9284087960985615, "lm_q1q2_score": 0.9020085336579869}}