[mapcode] 30/56: Fixed incorrect formatting of floats
Stefan Fritsch
sf at moszumanska.debian.org
Wed Nov 2 23:27:28 UTC 2016
This is an automated email from the git hooks/post-receive script.
sf pushed a commit to annotated tag v2.0.2
in repository mapcode.
commit 9d66565d7be137fd8a9a14747b699a784f04108a
Author: Rijn Buve <rijn at buve.nl>
Date: Fri Jun 19 16:18:42 2015 +0200
Fixed incorrect formatting of floats
---
utility/mapcode.cpp | 39 +++------------------------------------
1 file changed, 3 insertions(+), 36 deletions(-)
diff --git a/utility/mapcode.cpp b/utility/mapcode.cpp
index 883f130..573cce7 100644
--- a/utility/mapcode.cpp
+++ b/utility/mapcode.cpp
@@ -274,39 +274,6 @@ static void selfCheckMapcodeToLatLon(const char* territory, const char* mapcode,
}
}
-
-
-/**
- * The method asCoordinate() generates and returns a printable coordinate
- * precisely as it would be interpreted internally by mapcode encoding
- * (i.e. correctly rounded to the nearest one-millionth of a degree).
- * As target, pass a buffer for at least 12 characters (including zero termination).
- * If target = 0, an internal scratch buffer is used (the THIRD call will
- * overwrite the first call).
- */
-static char asCoordinateBuffer[24];
-static int ascoptr;
-static const char* asCoordinate(double coord, char* target)
-{
- long c = (long) ((coord * 1000000) + ((coord < 0) ? -0.5 : 0.5));
- int negative = (c < 0);
- if (negative) {
- c = -c;
- }
- if (target == 0) {
- ascoptr= ((ascoptr != 0) ? 0 : 12);
- target = &asCoordinateBuffer[ascoptr];
- }
- sprintf(target,"%s%d.%06d", (negative ? "-" : ""), (int) (c / 1000000), (int) (c % 1000000));
- return target;
-}
-
-
-/**
- * The method printMapcode() generates and outputs Mapcodes for a lat/lon pair.
- * If iShowError != 0, then encoding errors are output to stderr, otherwise they
- * are ignored.
- */
static void generateAndOutputMapcodes(double lat, double lon, int iShowError, int extraDigits, int useXYZ) {
char* results[MAX_NR_OF_MAPCODE_RESULTS];
@@ -328,7 +295,7 @@ static void generateAndOutputMapcodes(double lat, double lon, int iShowError, in
const int nrResults = encodeLatLonToMapcodes(results, lat, lon, context, extraDigits);
if (nrResults <= 0) {
if (iShowError) {
- fprintf(stderr, "error: cannot encode lat=%s, lon=%s)\n", asCoordinate(lat, 0), asCoordinate(lon, 0));
+ fprintf(stderr, "error: cannot encode lat=%.12g, lon=%.12g)\n", lat, lon);
exit(NORMAL_ERROR);
}
}
@@ -338,10 +305,10 @@ static void generateAndOutputMapcodes(double lat, double lon, int iShowError, in
double y;
double z;
convertLatLonToXYZ(lat, lon, &x, &y, &z);
- printf("%d %s %s %lf %lf %lf\n", nrResults, asCoordinate(lat, 0), asCoordinate(lon, 0), x, y, z);
+ printf("%d %.12g %.12g %.12g %.12g %.12g\n", nrResults, lat, lon, x, y, z);
}
else {
- printf("%d %s %s\n", nrResults, asCoordinate(lat, 0), asCoordinate(lon, 0));
+ printf("%d %.12g %.12g\n", nrResults, lat, lon);
}
for (int j = 0; j < nrResults; ++j) {
const char* foundMapcode = results[(j * 2)];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/mapcode.git
More information about the Pkg-grass-devel
mailing list