I'm trying to calculate the distance between two sets of coordinates, one set coming from a GPS module. I'm using the Haversine formula, which produces the correct answer when I enter it directly into Wolfram Alpha. I'm also using the TinyGPS library. Unfortunately, my code on the Arduino Duemilanove is not producing the correct answer, and I can't figure out why.
float flat, flon;
long dest_latitude = xx.xxxxxxxx;
long dest_longitude = -yy.yyyyyyyy;
int radius = 3956.6;
const float two = 2.0;
float delta_lat = radians(dest_latitude - flat);
float delta_lon = radians(dest_longitude - flon);
float a = square(sin(delta_lat/two)) + cos(radians (flat)) * cos(radians (dest_latitude)) * square(sin(delta_lon/two));
float c = two * asin(sqrt(a));
float d = radius * c;
(it goes on from here)
When I'm approximately 15.5 miles away from the destination coordinates, the Arduino board and GPS tell me I'm only 12.75 miles away. When I am at the destination coordinates, it tells me I'm 17.79 miles away. All of my calculations are floating point. What am I doing wrong?