The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

Entry #100045 - The SQL-Based Calculator

Last post 06-11-2007 12:09 PM by Alex Papadimoulis. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 06-11-2007 12:09 PM

    Entry #100045 - The SQL-Based Calculator

    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.
Page 1 of 1 (1 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems