Fix bug in algorithm for calculation approximate difference between two
distances