diff --git a/examples/searches/example_ternary_search_function_based.f90 b/examples/searches/example_ternary_search_function_based.f90 index 39f9d6f..b587781 100644 --- a/examples/searches/example_ternary_search_function_based.f90 +++ b/examples/searches/example_ternary_search_function_based.f90 @@ -1,12 +1,14 @@ -! Example Program: Function-based Ternary Search for Minimum and Maximum -! This program demonstrates how to use the function-based ternary search algorithm -! from the `ternary_search` module to find the minimum and maximum of unimodal functions. +!> Example Program: Function-based Ternary Search for Minimum and Maximum +!! +!! This program demonstrates how to use the function-based ternary search algorithm +!! from the `ternary_search` module to find the minimum and maximum of unimodal functions. program ternary_search_function_based use ternary_search implicit none ! Define the variables + integer, parameter :: dp = kind(0.0d0) ! Define double precision kind real(8) :: result_min, result_max ! Results for minimum and maximum values real(8) :: min_point, max_point ! Points where minimum and maximum occur real(8) :: left, right, tol ! Left and right bounds, and tolerance @@ -25,11 +27,11 @@ end function f_max ! The boundary values can vary depending on the problem context. ! In this example, they are chosen arbitrarily. - left = 0.0 - right = 10.0 + left = 0.0d0 + right = 10.0d0 ! The tolerance value defines how close the left and right bounds must be for the search to terminate. - tol = 1.0e-6 + tol = 1.0e-6_dp ! Call the ternary search to find the minimum point of f_min min_point = ternary_search_minimum(f_min, left, right, tol) @@ -51,7 +53,7 @@ end program ternary_search_function_based real(8) function f_min(x) real(8), intent(in) :: x - f_min = (x - 5.0)**2 + cos(x) ! Example of a quadratic function with a cosine oscillation + f_min = (x - 5.0d0)**2 + cos(x) ! Example of a quadratic function with a cosine oscillation end function f_min ! Define the unimodal function f_max with a maximum near x = 5.0 @@ -61,5 +63,5 @@ end function f_min real(8) function f_max(x) real(8), intent(in) :: x - f_max = -(x - 5.0)**2 + cos(x) ! Example of a quadratic function with a cosine oscillation + f_max = -(x - 5.0d0)**2 + cos(x) ! Example of a quadratic function with a cosine oscillation end function f_max diff --git a/modules/searches/ternary_search_module.f90 b/modules/searches/ternary_search_module.f90 index c144827..4674114 100644 --- a/modules/searches/ternary_search_module.f90 +++ b/modules/searches/ternary_search_module.f90 @@ -93,8 +93,8 @@ end function f ! Termination condition based on tolerance do while (r - l > tol) - mid1 = l + (r - l)/3.0 - mid2 = r - (r - l)/3.0 + mid1 = l + (r - l)/3.0d0 + mid2 = r - (r - l)/3.0d0 ! Compare function values at midpoints if (f(mid1) < f(mid2)) then @@ -105,7 +105,7 @@ end function f end do ! The minimum point is approximately at the midpoint - minimum = (l + r)/2.0 + minimum = (l + r)/2.0d0 end function ternary_search_minimum !> Function-based ternary search to find the maximum of a unimodal function @@ -134,8 +134,8 @@ end function f ! Termination condition based on tolerance do while (r - l > tol) - mid1 = l + (r - l)/3.0 - mid2 = r - (r - l)/3.0 + mid1 = l + (r - l)/3.0d0 + mid2 = r - (r - l)/3.0d0 ! Compare function values at midpoints if (f(mid1) > f(mid2)) then @@ -146,7 +146,7 @@ end function f end do ! The maximum point is approximately at the midpoint - maximum = (l + r)/2.0 + maximum = (l + r)/2.0d0 end function ternary_search_maximum end module ternary_search diff --git a/modules/sorts/merge_sort.f90 b/modules/sorts/merge_sort.f90 index 43d3c6b..7b6def5 100644 --- a/modules/sorts/merge_sort.f90 +++ b/modules/sorts/merge_sort.f90 @@ -23,7 +23,7 @@ recursive subroutine merge_sort(array, n) implicit none integer, dimension(:), intent(inout) :: array ! Input/output array to be sorted integer, intent(in) :: n ! Size of the array - integer :: middle, i + integer :: middle integer, dimension(:), allocatable :: left_half, right_half, sorted_array ! Base case: return if the array has 1 or fewer elements diff --git a/tests/sorts/tests_gnome_sort.f90 b/tests/sorts/tests_gnome_sort.f90 index 1e2bdae..fccf7a5 100644 --- a/tests/sorts/tests_gnome_sort.f90 +++ b/tests/sorts/tests_gnome_sort.f90 @@ -6,7 +6,6 @@ program tests_gnome_sort use gnome_sort_module implicit none - integer :: i integer, dimension(:), allocatable :: array ! Test 1: Repeated elements diff --git a/tests/sorts/tests_heap_sort.f90 b/tests/sorts/tests_heap_sort.f90 index 1961d80..0f34812 100644 --- a/tests/sorts/tests_heap_sort.f90 +++ b/tests/sorts/tests_heap_sort.f90 @@ -6,7 +6,6 @@ program tests_heap_sort use heap_sort_module implicit none - integer :: i integer, dimension(:), allocatable :: array ! Test 1: Repeated elements diff --git a/tests/sorts/tests_merge_sort.f90 b/tests/sorts/tests_merge_sort.f90 index 45af1fa..6242e16 100644 --- a/tests/sorts/tests_merge_sort.f90 +++ b/tests/sorts/tests_merge_sort.f90 @@ -6,7 +6,6 @@ program tests_merge_sort use merge_sort_module implicit none - integer :: i integer, dimension(:), allocatable :: array ! Test 1: Repeated elements diff --git a/tests/sorts/tests_quick_sort.f90 b/tests/sorts/tests_quick_sort.f90 index 262f251..3a20d0e 100644 --- a/tests/sorts/tests_quick_sort.f90 +++ b/tests/sorts/tests_quick_sort.f90 @@ -6,7 +6,6 @@ program tests_quick_sort use quick_sort_module implicit none - integer :: i integer, dimension(:), allocatable :: array ! Test 1: Repeated elements diff --git a/tests/sorts/tests_radix_sort.f90 b/tests/sorts/tests_radix_sort.f90 index 26dcc04..afce2ce 100644 --- a/tests/sorts/tests_radix_sort.f90 +++ b/tests/sorts/tests_radix_sort.f90 @@ -6,7 +6,6 @@ program tests_radix_sort use radix_sort_module implicit none - integer :: i integer, dimension(:), allocatable :: array integer, parameter :: base10 = 10, base2 = 2, base16 = 16