Category Archives: My Other Stuff

My Code

Calculating Large Numbers in C

As a corollary to my last post, it’s important to be careful when calculating file seek positions (if you’re skipping around that way). It turns out it’s necessary to cast all of the numbers being used when calculating a seek position to a large integer, such as unsigned long int.

By the way, Rob had some helpful comments on that last post. (Thanks Rob!)

Maintaining My Posting Rate

I had one major New-Year’s resolution (though I had resolved it before then): post to my blog on average once per day. This sounds simple, but I don’t just want one post on each day. I’m happy to let my posting muse cycle between wordlessness and logorrhea. Therefore, if I post three things one day, I’m off scot free for the next two days. In practice, this gets pretty hard to keep track of. I’ve already started to find it difficult 23 days into the year.

However, I was able to remedy this with a little PHP and MySQL code. WordPress (this blogging software) runs on those technologies, and so it was trivial for me to tap into the database and produce this page. It does something very simple. It goes from the beginning of the year to the present day, tallying posts along the way, and dividing by the number of days in the year that have passed. This gives me a total post count and a ratio of posts to days. As you can see if you look at that page, I have been coasting for a little while, but was getting dangerously close to “1”. This post should remedy that, which is kind of cheating, but I’m willing to accept it.

Probably this could be dressed up into a widget or plugin or something, and anyone is welcome to use it to do that, but I have neither the time nor sufficient interest to learn how.
Here’s the PHP code, if you’re interested: postcountphp.gz (1 kB)

ADDENDUM: Updated 2008-01-26 to only count published posts.

Float vs. Double

Someone in the lab recently came to me asking for help in diagnosing a strange problem. The time output from their program was drifting inexplicably — that is, they were adding a certain increment every iteration, but the time was changing by some value slightly different from that increment. It turns out that this was because they were using single-precision floating-point (a.k.a “float”) variables. The problem did not show up right away. In fact, it would not have been an issue were they not adding an increment so very many times.

To diagnose this problem, (because I haven’t dealt with this issue in a long while), I wrote this little piece of code:
Continue reading

Using UNIX (and Linux) for Research in silicio

There is a rank list of the most powerful computers on the planet: Top500.org. (It looks like they’ve recently done a site redesign for the better.) Statistics on these computers are available here. Of the top 500 most powerful computers on the planet, a measly 1.20% run a non-UNIX operating system (OS). 76.20% run an unspecified Linux (compared with, say a certain version of Red Hat or SuSE linux). According to the overall family rankings here, a total of 85.20% run some variant of Linux. The remaining operating systems on the list are all various UNIXes, including BSD and Mac OS X.
Continue reading