Switch to bash's built-in math operators for a huge speed increase
This could potentially be rewritten in C for an even bigger speedup.