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

Assumption - host word size
(Assumption - host word size)
Line 125:
 
: It's a little complex (there's multiple representations of integers under the covers; small numbers are stored as C <code>long</code>s and slightly larger ones as <code>long long</code>s, assuming this is on a platform where those are a different type) but effectively (and simplifying vastly) it's 0xF0 plus some metadata to trigger the generation additional 0xFF bytes on the left as necessary, i.e., it stores that the number is negative. The actual padding out is done on the fly as forced by other code. However, the abstract model is indeed of an unbounded number of bits (just as a positive number would have an unbounded number of zero bits to the left). It just doesn't ever actually need that many for any even vaguely-reasonable number. :-) Of course, users of Tcl hardly ever have to deal with this: they're either in scripts — and so are using the abstract model — or they're in C and want a particular native numeric type; Tcl's implementation hides the gory details away unless they're writing C code that needs to efficiently operate on both small numbers and full bignums. That's kind-of rare in practice. –[[User:Dkf|Donal Fellows]] 03:40, 9 December 2011 (UTC)
== Assumption - host word size ==
Not all languages know about their host word size. Implementing an "efficient" algorithm without loops or recursion for this special case is a bit arbitrary and dodgy in these cases. Sure an arbitrary special case could be coded but would that be efficient? What actually makes sense here? --[[User:Dgamey|Dgamey]] 18:45, 9 December 2011 (UTC)
Anonymous user