Article 1NGKR CodeSOD: It's Log, Log, Log

CodeSOD: It's Log, Log, Log

by
Ellis Morning
from The Daily WTF on (#1NGKR)

512px-Logarithm_keys.jpg

Reader Bernie submits for our approval this wonderful C# log base 2 implementation. He says: "We can distinguish two halves in that code. It looks like it was originally written for an unsigned 16-bit int, and later on extended for signed 32-bit integers."

This code reminds me of the change-sorting machine I have in my closet, which sorts change based on weight. That thing has no error handling if you try to sort, say, a huge boulder through it; it'd just fall apart. At least here, we have the assurance that the universe's biggest numbers all have a log base 2 of 31.

public static int Log2(int x) { if (x 
release50.png[Advertisement] Release!is a light card game about software and the people who make it. Play with 2-5 people, or up to 10 with two copies - only $9.95 shipped! TheDailyWtf?d=yIl2AUoC8zAO6k6IitOQnk
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments