Finished implementation of math functions