S
Steve Zimmerman
I'm not even a billionth of the programmer that a
real expert is (Heathfield, Amdahl, Tisdale, et al),
and I couldn't code the following log function myself,
but I found it interesting, so I am sharing it with
the group. Here is a simple function to calculate
log base 2 of n:
int log2 (int n)
{
int log = 0;
while (n > 1) {
n /= 2;
log++;
}
return log;
}
Am I alone in experiencing this function as exceedingly
pleasant? That's not a rhetorical question; I'm really
wondering. Some of the so-called experts are so spiteful
and backbiting that I suspect their jobs are depriving them
of all the pleasure of the C programming language.
Their loss.
(The quoted function is from _C Programming: A Modern Approach_,
p. 185.)
real expert is (Heathfield, Amdahl, Tisdale, et al),
and I couldn't code the following log function myself,
but I found it interesting, so I am sharing it with
the group. Here is a simple function to calculate
log base 2 of n:
int log2 (int n)
{
int log = 0;
while (n > 1) {
n /= 2;
log++;
}
return log;
}
Am I alone in experiencing this function as exceedingly
pleasant? That's not a rhetorical question; I'm really
wondering. Some of the so-called experts are so spiteful
and backbiting that I suspect their jobs are depriving them
of all the pleasure of the C programming language.
Their loss.
(The quoted function is from _C Programming: A Modern Approach_,
p. 185.)