About The Contest

The first ever Olympiad of Misguided Geeks contest at Worse Than Failure (or OMGWTF for short) is a new kind of programming contest. Readers are invited to be creative with devising a calculator with the craziest code they can write. One lucky and potentially insane winner will get either a brand new MacBook Pro or comparable Sony VAIO laptop.



Entry #100045: The SQL-Based Calculator

by Stephen Oberholtzer
This is the ultimate nightmare.

For a short description, a line from the README file sums this up:

I would not force my own worst enemy to maintain this code.

Internally, all values are stored as in a base-10 floating-point format: a structure containing an array of digits, the sign, and the number of digits before the decimal point. Basically, a string.

Over 64K lines (2MB!) of the program is a public-domain database engine called SQLite.

All calculations in the program are done by breaking them down into the following three primitives:

1. Adding two digits and a carry digit.
2. Subtracting two digits and a carry digit.
3. Multiplying two digits and adding a carry digit.

These three primitives are themselves implemented by looking them up in an in-memory SQL database that basically maps (digit1, digit2, carry) to (newdigit, newcarry).

Addition and subtraction are easy; multiplication is achieved by a combination of single-digit multiplication and addition. Division is achieved by repeated subtraction and manipulation of the decimal point.

Like my other "good" entry, the Overkill Calculator, this program is fairly straightforward, with plenty of comments -- only the theory behind its implementation is insane. Extremely-insane. Keep a bucket by your PC in case your brain melts.

Download0 Comments