Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- integer function binsearch(tab, el)
- implicit none
- real, intent(in) :: tab(:), el
- integer :: a, b, mid
- a = 1
- b = size(tab)
- do while (b - a > 1)
- mid = (a + b)/2
- if (el >= tab(mid)) then
- a = mid
- else
- b = mid
- endif
- ! if (el < tab(mid + 1)) exit ! BAD OPTIMIZATION !
- enddo
- binsearch = a
- end function binsearch
- foo = binsearch(tab, el)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement