I went Hiking on June 19, 2004 with Dan Crouse to the top of Silver Peak, located in Snoqualmie. I had not gone hiking in a while (years?), and it was rough. Dan drove us, which was good, as I was in no condition to drive afterwards. I made a photojournal of the hike and a panorama [4MB QTVR] at the top.
const float v; // compute c = int(log2(v))
int x = *(int *)&v;
int c = x >> 23;
if (c == 0) {
// handle subnormals
while ((x & 0x400000) == 0) {
x <<= 1;
c--;
}
}
return c - 127;
I didn't like the idea that the code would loop indefinately, so I replaced the loop, which computes the integer log base 2 of the mantissa, with a version that computes it via table lookup; it is slightly modified from the general case, since we need only deal with 23 bits. It should be faster than the code above.
const float v; // find int(log2(v)), where v > 0.0 && finite(v)
const int x = *(int *) &v;
int c = x >> 23; // c gets the result;
if (c)
{
c -= 127;
}
else
{ // subnormal, so recompute using mantissa: c = intlog2(x) - 149;
register unsigned int t; // temporary
// Note that LogTable256 was defined earlier
if (t = x >> 16)
{
c = LogTable256[t] - 133;
}
else
{
c = (t = x >> 8) ? LogTable256[t] - 141 : LogTable256[x] - 149;
}
}
r = (v ^ (v >> (sizeof(int) * 8 - 1))) + ((unsigned) v >> (sizeof(int) * 8 - 1)) for anyone interested in avoiding the patented method for computing the integer absolute value without branching, though his takes another operation. I added my own variation of it, r = (v ^ (v >> (sizeof(int) * 8 - 1))) + (v < 0), which takes as many operations, though gcc generated fewer x86 instructions for it (4) than his (5). The patented version is still the best at 3.
Another variation came to mind, but I didn't think it sufficiently portable:
union {long long ll; int i[2];} t;
t.ll = v; // sign-extend
r = (t.i[0] ^ t.i[1]) - t.i[ BYTE_ORDER == LITTLE_ENDIAN];
A couple months ago I was helping my dad set up a new computer at his office, and nearby, I noticed that one of his employees had a wheel mouse that didn't work very well. It was an older mouse with a rubber ball for positioning, but new enough to have a scroll wheel on top. I could hardly move the scroll wheel and the mouse ball's encoders were gunked up. I took it apart and cleaned it. But the scroll wheel still didn't work. So I repeatedly disassembled it further than before and cleaned it more, and finally it basically worked. The problem was that there was so much gunk — hand lotion, dead skin cells, oil, dirt, lint, etc. — that the rotational encoders were not moving. Applying more force to rotate the scroll wheel only caused it to depress (as it is also a button). I appreciate tactile feedback, but the experience left me wishing it was a fully optical mouse even in the scroll wheel. Mice are not built to make cleaning the scroll wheel encoder easy (they must be taken apart with a screw driver), and if this older mouse is typical, many will need their scroll wheel encoders cleaned in time.
The obvious solution is to use an optical system, such as is used to determine positional motion in newer mice. These optical mice use a simple two-dimensional array of CMOS or CCD light sensors and an LED to illuminate the surface over which they move; some logic determines how the mouse is moving in orthogonal directions. What I would like is an optical mouse that also has an optical scrolling sensor on top, shaped approximately like scroll wheels are, but shorter and unmoving. The transparent scroll hump would detect the degree a finger moves over it forward and backward and operate vertical scroll bars like mouse scroll wheels now do. Moving left and right would control horizontal scroll bars. If pressed, the hump would also act as a middle button of course. The focus of the light sensor would need to be limited to immediately above the top surface of the scroll hump to prevent false readings, such as movements by the user to grasp the mouse. The user's finger should probably be illuminated over the scroll hump by an infrared LED, which would not irritate users' eyes as does looking directly at the red LEDs that optical mice currently employ.
I have not seen anything like this on the market, and I think it would be a good product. Unfortunately, my dad says he has written patents for Microsoft's mice and would have a conflict of interest in representing me on this, thus I don't have the resources to patent it. C'est la vie. Oh well, it's probably obvious anyways.
I've been a vegetarian since around 1991. I noticed that a number of products have no mention of meat in their ingredients list, but they do use natural flavor. In particular, Rosarita No Fat Traditional Refried Beans include this mysterious substance. I therefore wrote a (real) letter to Rosarita Consumer Affairs. They recently replied back via telephone — the beans are not vegetarian. Mystery solved. Unfortunately many people seem to assume the opposite, such as Shopping Vegan.
My letter:
[my address, phone, and email info]
May 20, 2004
Rosarita Consumer Affairs
P.O. Box 57078
Irvine, CA 92619-7078
RE: Are Rosarita No Fat Traditional Refried Beans vegetarian?
Dear Helpful Person:
I applaud Rosarita for selling Rosarita Vegetarian Refried Beans because I wish to avoid eating meat, as do some of the people for whom I cook. I was wondering if another product, Rosarita No Fat Traditional Refried Beans, is also vegetarian. I notice the ingredients include "natural flavor," which is highly ambiguous; e.g., it may be chicken or beef stock. Could you please tell me what the "natural flavor" is?
It would be helpful if the labels on the cans clearly indicated that the contents were not vegetarian (or vegan) if that is the case. Thank you for your time.
Yours sincerely,
Sean Anderson
Their reply:
UPDATE 2004-06-29:
ConAgra also sent me a letter, which I scanned it in:

I received an email from a Sean A. Irvine in New Zealand earlier this week. He was reading my bithacks page and suggested that I mention sign extending. I guess he uses Java, which doesn't have the bit fields feature that C has. I wrote three entries for sign extending, depending on if you have the bit fields of C and a fixed bit width or want something standard for variable bit widths or want something quick and dirty again for variable bit widths.
For the last year or so I have been flossing my teeth by first tying together the ends of around 12" of floss, thus forming a loop. The benefit of doing so is that it doesn't slip through my fingers when (wet and) I want make the floss taunt; I simply pull my hands apart.
I realize that there are devices that can hold floss between the ends of two small rigid arms, but I have found them ungainly compared to using my fingers. My dental hygienist said she would like to have floss in loops too. Floss that is manufactured in loops would sell better than the standard spools available today, I believe. It would make a nice product (just give me a piece of the action and some free samples for the idea).
UPDATE 2004-06-10 10:05:
Last night David pointed me to a website of a manufacturer, Floss Loops. I will try to find a way to buy it.
At The Good Guys, for about $270, my dad just bought a Roku HD1000, which is basically a embedded Linux appliance that hooks into the HDTV and shows movies and pictures and plays music from either flash memory cards or off the LAN. In short, it's a high definition networked digital media player. He read a bunch of reviews of similar products and all of them required a program to run on a Windows PC to download files, with the Roku being the sole exception. (That didn't suit us, since we are using a Linux machine as our file server.) Overall, it seems like a nice unit. They even provide an SDK to assist the hacker crowd in writing custom applications on it. (I downloaded it, but have not written anything yet.) A negative is the remote control is rather directional, and if a Compact Flash card is inserted (near the IR sensor), some angles are unusable. My dad has a programmable remote (a Pronto), for which Roku Labs provides a template, and the Pronto supposedly works better than the remote provided.
I used telnet on one of the computers to log into it and poked around. It is basically a 300MHz MIPS R4000 CPU with 64MB of RAM and about 32MB of built-in flash memory. It supports Compact Flash cards like my camera uses as well as Smart Media, Memory Stick, SD/MMC.
I took a walk today with my dad and the dogs. All of us need the exercise. My dad asked about the temperature before we left, to bring a coat if cold. I felt the air and it wasn't too bad, so I said, "Do not bring a coat." He didn't. But as we walked the air became increasingly humid and dark clouds loomed overhead. The wind picked up. And then the first few sprinkles fell, increasing to rain. We took shelter under a big maple tree, about 10 minutes from home, with the hope that we were experiencing an ephemeral shower. However, the wind and rain waxed. My dad decided we should just head home rather than wait, so we started walking, and the rain deluged us. He mentioned something about someone writing a Ph.D. on walking versus running in the rain, which I found hard to believe. (It's better to run, as shown by a simulation by Ken Holmes.) I felt bad for encouraging him to take a walk and then for him and the dogs to be rained upon, so I ran the rest of the way home and drove my pickup truck to haul them the last few blocks.
I was reflecting on the aftereffects of Reagan, now that he has passed away. I think his greatness is often overestimated. He is considered the "Great Communicator," and I will concede that he was a good charismatic speaker. But actions speak louder, and his actions have left our country heavily and unnecessarily in debt. The late USSR would have eventually imploded economically had we not built so many nuclear missiles, for example. Even if it hadn't collapsed, the USSR would have eventually recognized that communism is not as efficient as capitalism, and changed as China has. There are tons of interesting statistics on the effects of Reaganomics on-line. His outrageous deficit spending set a precedent that has been followed to a lesser degree by subsequent presidents and congressmen. Balanced budgets are never made. I'm afraid that in decades our country may be drowning in debt. Our taxpaying citizens shall waste an increasing fraction of our domestic product on the interest. The debt is currently over 7 trillion dollars and climbing.
ADDENDUM 2004-06-08 10:00:
I have been getting several hits by people looking for information about Reagan's lies. Rotten.com has a bio of Reagan, with some discussion of the Iran-Contra lies. It is not the most comprehensive, but I enjoy reading Rotten.com's biographies.