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 #100085: Calc a la WTF too
by Bertho Stultiens
The basics of the GUI is standard GTK stuff. The calculator is a generic parsetree ASCII encoded BigEndian BCD implementation without precedence distinction. There are no processor supported multiplications or divisions but only addition, subtraction and table lookup (10x10) for multiplication.
There is no limitation on how big or small numbers may become if you have enough memory and stack (running out of stack gives a segfault; a stack of 10MByte gives about 8000 decimal places, your mileage may vary). Try sequence "2*=*=*=*=*=*=*=*=*=*=*=*=*=*=" for a set of 2^2, 2^4, 2^8, 2^16, 2^32, 2^64, 2^128,... if you can get it to fit onto your screen; the widget does not autosize. Or sequence 1/2*=*=... for small numbers.
Calculations should have an approximate complexity of:
- addition O(n)
- subtraction positive result O(n)
negative result O(2*n+1)
- multiplication O(2*n*m)
- division O(4*log2(10)*m*(|n-m|+1)^2)
where n and m are number of digits in resp. left and right value or the maximum of either side in case of add/sub. The subtraction is not constant because of the calculation of the 2's complement in case of a negative result. Addition and substrations are remapped according to the sign on entry (-a+b = b-a constructs). The complexities do not account for the administrative overhead for fractions and signs, but these are small compared to the actual calculations. (for the theoretical correctness of notation purists: ignore the constants and set m == n)