function that calculates half