From 63e7cf810c5a622d6c8d829cdcefcfb16ac7e702 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 13 May 2015 00:26:12 +0200 Subject: [PATCH] fixing unintended integer division --- src/algorithms/PVT/libs/gps_l1_ca_ls_pvt.cc | 22 ++++++++++----------- src/algorithms/PVT/libs/hybrid_ls_pvt.cc | 18 ++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/algorithms/PVT/libs/gps_l1_ca_ls_pvt.cc b/src/algorithms/PVT/libs/gps_l1_ca_ls_pvt.cc index d58cc73df..3dde38bad 100644 --- a/src/algorithms/PVT/libs/gps_l1_ca_ls_pvt.cc +++ b/src/algorithms/PVT/libs/gps_l1_ca_ls_pvt.cc @@ -489,24 +489,24 @@ void gps_l1_ca_ls_pvt::cart2geo(double X, double Y, double Z, int elipsoid_selec 4. World Geodetic System 1984 */ - const double a[5] = {6378388, 6378160, 6378135, 6378137, 6378137}; - const double f[5] = {1/297, 1/298.247, 1/298.26, 1/298.257222101, 1/298.257223563}; + const double a[5] = {6378388.0, 6378160.0, 6378135.0, 6378137.0, 6378137.0}; + const double f[5] = {1.0 / 297.0, 1.0 / 298.247, 1.0 / 298.26, 1.0 / 298.257222101, 1.0 / 298.257223563}; double lambda = atan2(Y,X); - double ex2 = (2 - f[elipsoid_selection]) * f[elipsoid_selection] / ((1 - f[elipsoid_selection])*(1 - f[elipsoid_selection])); - double c = a[elipsoid_selection] * sqrt(1 + ex2); - double phi = atan(Z / ((sqrt(X*X + Y*Y)*(1 - (2 - f[elipsoid_selection])) * f[elipsoid_selection]))); + double ex2 = (2.0 - f[elipsoid_selection]) * f[elipsoid_selection] / ((1.0 - f[elipsoid_selection]) * (1.0 - f[elipsoid_selection])); + double c = a[elipsoid_selection] * sqrt(1.0 + ex2); + double phi = atan(Z / ((sqrt(X * X + Y * Y) * (1.0 - (2.0 - f[elipsoid_selection])) * f[elipsoid_selection]))); double h = 0.1; - double oldh = 0; + double oldh = 0.0; double N; int iterations = 0; do { oldh = h; N = c / sqrt(1 + ex2 * (cos(phi) * cos(phi))); - phi = atan(Z / ((sqrt(X*X + Y*Y) * (1 - (2 -f[elipsoid_selection]) * f[elipsoid_selection] *N / (N + h) )))); - h = sqrt(X*X + Y*Y) / cos(phi) - N; + phi = atan(Z / ((sqrt(X*X + Y*Y) * (1.0 - (2.0 -f[elipsoid_selection]) * f[elipsoid_selection] * N / (N + h) )))); + h = sqrt(X * X + Y * Y) / cos(phi) - N; iterations = iterations + 1; if (iterations > 100) { @@ -516,7 +516,7 @@ void gps_l1_ca_ls_pvt::cart2geo(double X, double Y, double Z, int elipsoid_selec } while (std::abs(h - oldh) > 1.0e-12); d_latitude_d = phi * 180.0 / GPS_PI; - d_longitude_d = lambda * 180 / GPS_PI; + d_longitude_d = lambda * 180.0 / GPS_PI; d_height_m = h; } @@ -586,7 +586,7 @@ void gps_l1_ca_ls_pvt::togeod(double *dphi, double *dlambda, double *h, double a } else { - sinphi = 0; + sinphi = 0.0; } *dphi = asin(sinphi); @@ -605,7 +605,7 @@ void gps_l1_ca_ls_pvt::togeod(double *dphi, double *dlambda, double *h, double a double N_phi; double dP; double dZ; - double oneesq = 1 - esq; + double oneesq = 1.0 - esq; for (int i = 0; i < maxit; i++) { diff --git a/src/algorithms/PVT/libs/hybrid_ls_pvt.cc b/src/algorithms/PVT/libs/hybrid_ls_pvt.cc index cd644c0fe..84b6ca34a 100644 --- a/src/algorithms/PVT/libs/hybrid_ls_pvt.cc +++ b/src/algorithms/PVT/libs/hybrid_ls_pvt.cc @@ -584,24 +584,24 @@ void hybrid_ls_pvt::cart2geo(double X, double Y, double Z, int elipsoid_selectio 4. World Geodetic System 1984 */ - const double a[5] = {6378388, 6378160, 6378135, 6378137, 6378137}; - const double f[5] = {1/297, 1/298.247, 1/298.26, 1/298.257222101, 1/298.257223563}; + const double a[5] = {6378388.0, 6378160.0, 6378135.0, 6378137.0, 6378137.0}; + const double f[5] = {1.0 / 297.0, 1.0 / 298.247, 1.0 / 298.26, 1.0 / 298.257222101, 1.0 / 298.257223563}; double lambda = atan2(Y, X); - double ex2 = (2 - f[elipsoid_selection]) * f[elipsoid_selection] / ((1 - f[elipsoid_selection])*(1 - f[elipsoid_selection])); - double c = a[elipsoid_selection] * sqrt(1+ex2); - double phi = atan(Z / ((sqrt(X*X + Y*Y)*(1 - (2 - f[elipsoid_selection])) * f[elipsoid_selection]))); + double ex2 = (2.0 - f[elipsoid_selection]) * f[elipsoid_selection] / ((1.0 - f[elipsoid_selection]) * (1.0 - f[elipsoid_selection])); + double c = a[elipsoid_selection] * sqrt(1.0 + ex2); + double phi = atan(Z / ((sqrt(X * X + Y * Y) * (1.0 - (2.0 - f[elipsoid_selection])) * f[elipsoid_selection]))); double h = 0.1; - double oldh = 0; + double oldh = 0.0; double N; int iterations = 0; do { oldh = h; N = c / sqrt(1 + ex2 * (cos(phi) * cos(phi))); - phi = atan(Z / ((sqrt(X*X + Y*Y) * (1 - (2 - f[elipsoid_selection]) * f[elipsoid_selection] *N / (N + h) )))); - h = sqrt(X*X + Y*Y) / cos(phi) - N; + phi = atan(Z / ((sqrt(X * X + Y * Y) * (1.0 - (2.0 - f[elipsoid_selection]) * f[elipsoid_selection] * N / (N + h) )))); + h = sqrt(X * X + Y * Y) / cos(phi) - N; iterations = iterations + 1; if (iterations > 100) { @@ -611,7 +611,7 @@ void hybrid_ls_pvt::cart2geo(double X, double Y, double Z, int elipsoid_selectio } while (std::abs(h - oldh) > 1.0e-12); d_latitude_d = phi * 180.0 / GPS_PI; - d_longitude_d = lambda * 180 / GPS_PI; + d_longitude_d = lambda * 180.0 / GPS_PI; d_height_m = h; }