Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
  • Loading branch information
0382 and jvdp1 authored May 17, 2023
commit d49178a29995a68e68a7e6450a3f40c08dcb9dd3
7 changes: 4 additions & 3 deletions example/sorting/example_radix_sort.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ program example_radix_sort
implicit none
integer(int8), allocatable :: arri8(:)
integer(int16), allocatable :: arri16(:)
real(dp), allocatable, target :: arrf64(:), x
real(dp) :: x
real(dp), allocatable :: arrf64(:)

arri8 = [-128, 127, 0, -1, 1]
call radix_sort(arri8)
Expand All @@ -19,7 +20,7 @@ program example_radix_sort
arrf64 = [1.0_dp/x, 0.0_dp, 0.0_dp/x, -1.0_dp/x, -0.0_dp, 1.0_dp, -1.0_dp, 3.45_dp, -3.14_dp, 3.44_dp]
call radix_sort(arrf64)
print *, arrf64
! In my computer, it gives
! Expect output:
! nan, -inf, -3.14, -1.0, -0.0, 0.0, 1.0, 3.44, 3.45, inf
! but the position of nan is undefined, the position of `±inf`, `±0.0` is as expected
! Note: the position of nan is undefined
end program example_radix_sort
4 changes: 2 additions & 2 deletions src/stdlib_sorting_radix_sort.f90
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ pure module subroutine int16_radix_sort(array, work, reverse)
end if
call radix_sort_u16_helper(N, array, buffer)
! After calling `radix_sort_u<width>_helper. The array is sorted as unsigned integers.
! In the view of signed arrsy, the negative numbers are sorted but in the tail of the array.
! Use binary search to find the boundary, and move then to correct position.
! In the view of signed array, the negative numbers are sorted but in the tail of the array.
! Use binary search to find the boundary, and move them to correct position.
if (array(1) >= 0 .and. array(N) < 0) then
start = 1
end = N
Expand Down