Inspiration
Before this hackathon, I had yet to find a decent calculator on the App Store that not only had base conversion but also could work with arbitrarily large numbers (aka bignumbers or bigintegers).
What it does
procalc is an arbitrary-precision calculator that can perform integer arithmetic and bitwise operations in different bases. The goal was to create a calculator that could compute what ordinary calculators could not. Notable features:
- Arbitrary precision: this is probably the greatest advantage that procalc has over other calculators.
- Base conversion: procalc can calculate in any base from 2 to 36 inclusive. The keypad contains alphabetical characters to account for base 36.
- Bitwise functions: AND, OR, XOR, LSHIFT, RSHIFT, and NOT are implemented. AND, OR, and XOR are not arbitrary precision.
- Stack-based model: procalc uses a stack/list of bigintegers for memory, and there are specific functions to manipulate the stack; this allows for a simple simulation of parentheses in infix ("normal") notation.
- Postfix notation: Instead of
1+2, expressions are evaluated as1 2+. This is more suitable for a stack-based model and is actually easier to implement.
How it was built
The javascript-bignum library was extended to fit the calculator's arbitrary precision specs. jQuery was used for UI magic, but the general design was self-made. Instead of HTML, I used an HTML preprocessor called Jade to speed up programming.
Instead of creating a native iOS app, I made a web app instead, and used various HTML hacks to allow the website to behave just like an iOS app (and even work offline!).
Challenges faced during creation
- There were many UI bugs that had to be fixed (ex.: the grid for the keypad had serious formatting problems in the beginning). This was exclusively a CSS problem, however.
- Implementing arbitrary-precision bitwise operations was very difficult and required a lot of "creative" thinking (ex.:
bitwise NOT of a == -a-1). - Javascript, being the backwards language it really is, only supports 32-bit integers, meaning that it was very easy for numbers to "overflow" and become wildly inaccurate. Extending and building off of an existing biginteger library solved this problem (at least, for now).
To-do list
- Start implementing arbitrary floating-point support (meaning more functions!).
- Make bitwise AND, OR, and XOR arbitrary-precision.
- Create a way to manipulate the bits of each number individually.
- Support bases greater than 36.
Log in or sign up for Devpost to join the conversation.