aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Gubler <thomasgubler@gmail.com>2014-08-11 15:29:59 +0200
committerThomas Gubler <thomasgubler@gmail.com>2014-08-11 15:29:59 +0200
commit5baf9cea0d8fcf6e0c6b3c92b26167067e9cb0fa (patch)
tree1701234d8d46601c6db82ed480060261fbac30ec
parent89986cf3e5cc8a9e18d56fe971d3e089232e3beb (diff)
downloadpx4-firmware-5baf9cea0d8fcf6e0c6b3c92b26167067e9cb0fa.tar.gz
px4-firmware-5baf9cea0d8fcf6e0c6b3c92b26167067e9cb0fa.tar.bz2
px4-firmware-5baf9cea0d8fcf6e0c6b3c92b26167067e9cb0fa.zip
geo: fix some warnings
-rw-r--r--src/lib/geo/geo.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/lib/geo/geo.c b/src/lib/geo/geo.c
index ad1ff37e3..1c8d2a2a7 100644
--- a/src/lib/geo/geo.c
+++ b/src/lib/geo/geo.c
@@ -50,6 +50,7 @@
#include <math.h>
#include <stdbool.h>
#include <string.h>
+#include <float.h>
#include <systemlib/err.h>
#include <drivers/drv_hrt.h>
@@ -147,7 +148,7 @@ __EXPORT int map_projection_project(const struct map_projection_reference_s *ref
double cos_d_lon = cos(lon_rad - ref->lon_rad);
double c = acos(ref->sin_lat * sin_lat + ref->cos_lat * cos_lat * cos_d_lon);
- double k = (c == 0.0) ? 1.0 : (c / sin(c));
+ double k = (fabs(c) < DBL_EPSILON) ? 1.0 : (c / sin(c));
*x = k * (ref->cos_lat * sin_lat - ref->sin_lat * cos_lat * cos_d_lon) * CONSTANTS_RADIUS_OF_EARTH;
*y = k * cos_lat * sin(lon_rad - ref->lon_rad) * CONSTANTS_RADIUS_OF_EARTH;
@@ -175,7 +176,7 @@ __EXPORT int map_projection_reproject(const struct map_projection_reference_s *r
double lat_rad;
double lon_rad;
- if (c != 0.0) {
+ if (fabs(c) > DBL_EPSILON) {
lat_rad = asin(cos_c * ref->sin_lat + (x_rad * sin_c * ref->cos_lat) / c);
lon_rad = (ref->lon_rad + atan2(y_rad * sin_c, c * ref->cos_lat * cos_c - x_rad * ref->sin_lat * sin_c));