Removed useless const qualifications for integer return types.
Removed redundant flush instructions.
Used std::atan2 to handle most of the work in get_distance.