Skip to content

Commit

Permalink
geocentric_radius(): reduce number of additions and multiplications
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Mar 16, 2024
1 parent 73ebe8e commit 36da998
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/conversions/cart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,15 @@ static double geocentric_radius(double a, double b_div_a, double cosphi,
// const double b = a * b_div_a;
// return hypot(a * a * cosphi, b * b * sinphi) /
// hypot(a * cosphi, b * sinphi);

const double cosphi_squared = cosphi * cosphi;
const double sinphi_squared = sinphi * sinphi;
const double b_div_a_squared = b_div_a * b_div_a;
const double b_div_a_squared_mul_sinphi_squared =
b_div_a_squared * sinphi_squared;
return a *
sqrt(cosphi * cosphi +
(b_div_a * b_div_a) * (b_div_a * b_div_a) * (sinphi * sinphi)) /
sqrt(cosphi * cosphi + (b_div_a * b_div_a) * (sinphi * sinphi));
sqrt(cosphi_squared +
b_div_a_squared * b_div_a_squared_mul_sinphi_squared) /
sqrt(cosphi_squared + b_div_a_squared_mul_sinphi_squared);
}

/*********************************************************************/
Expand Down

0 comments on commit 36da998

Please sign in to comment.