Math.c implemented in pure ruby