Find first and last set bit of a long integer: Difference between revisions

Content added Content deleted
Line 609: Line 609:
Even though Fortran has intrinsic functions, and modern machines have special instructions for the task, it still seems worthwhile to write out functions.
Even though Fortran has intrinsic functions, and modern machines have special instructions for the task, it still seems worthwhile to write out functions.


One thing that is evident, if you study the various ways to implement these functions, is that Fortran is ill suited, in a way most high-level languages have been ill-suited since the beginning of time: they do not have built in ''unsigned'' integers ''with overflow explicitly allowed''. ISO standard C does (and thus so does ATS, because its integers are exactly C integers). But this is unusual, outside of C and its relatives, and (I would imagine) owes to C's origins as a replacement for assembly language.
One thing that is evident, if you study the various ways to implement these functions, is that Fortran is ill suited, in a way most high-level languages have been ill suited since the beginning of time: they do not have built in ''unsigned'' integers with ''overflow explicitly allowed''. ISO standard C does (and thus so does ATS, because its integers are exactly C integers). But this is unusual, outside of C and its relatives, and (I would imagine) owes to C's origins as a replacement for assembly language.


<lang fortran>! As was already pointed out, Fortran already has intrinsic functions
<lang fortran>! As was already pointed out, Fortran has intrinsic functions that
! that should compile to efficient code, such as a single machine
! should compile to efficient code, such as a single machine
! instruction. But it seems profitable to have written implementations
! instruction. But it seems profitable to have written implementations
! according to the full task description, and also by other methods.
! according to the full task description, and also by other methods.