Changed implementation to not include functions from math.h