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

Content deleted Content added
m →‎{{header|Icon}} and {{header|Unicon}}: performance tweak and description
Line 239:
 
=={{header|Icon}} and {{header|Unicon}}==
The task definition makes some assumptions that don't work in Icon/Unicon and are going to require some reinterpretation. In Icon/Unicon all integers appear to be implemented as a single common type. A specific implementation may or may not have large integers, but if it does they are essentially indistinguishable from regular integers. Given this implementing "efficient" procedures for the platform word size without loops or recursion makes little sense. Instead these lsb and msb routines are generalized to reduce the integer in blocks of bits and then zoom in on the desired bit by binary search (i.e. successively looking a blocks that are half the size again). The initial power for the mask size in xsb_initial should be chosen so that the largest mask used is the word size of the implementation so that we don't create unnecessary large integers through implicit type conversion.
 
<lang Icon>link printf,hexcvt
Line 293:
initial { # build
mask := []
p := 3230 * 2 # for 32 bits, 30 ==> 2^31-1 mask
until (p := p / 2) = 0 do put(mask,2^p-1,-p)
}