yakra / DataProcessing

Data Processing Scripts and Programs for Travel Mapping Project
0 stars 0 forks source link

Waypoint::distance_to: square doubles without using pow #267

Open yakra opened 9 months ago

yakra commented 9 months ago
    // haversine formula
    double sinsq_lat = sin((rlat2-rlat1)/2); sinsq_lat *= sinsq_lat;
    double sinsq_lng = sin((rlng2-rlng1)/2); sinsq_lng *= sinsq_lng;
    double ans = asin(sqrt(sinsq_lat + cos(rlat1) * cos(rlat2) * sinsq_lng)) * 7926.2; /* EARTH_DIAMETER */

Is it possible the compiler optimizes away calls to pow(foo,2) anyway? Probably very little time saved, lost in the noise of ReadWptThread. Cook up a test case with a few million random numbers.