Skip to content

Commit 1d1493b

Browse files
committed
Decode() now always returns (nan, nan) when decoding fails.
1 parent aaf4aa3 commit 1d1493b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

mapcodemodule.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "Python.h"
1818
#include "mapcoder.c"
19-
19+
#include <math.h>
2020

2121
static char version_doc[] =
2222
"version() -> string\n\
@@ -56,7 +56,7 @@ static char decode_doc[] =
5656
Decodes the provided string to latitude and longitude. Optionally\n\
5757
a territoryname can be provided to disambiguate the mapcode.\n\
5858
\n\
59-
Returns (999,999) when decoding failed.\n";
59+
Returns (nan,nan) when decoding failed.\n";
6060

6161
static PyObject *decode(PyObject *self, PyObject *args)
6262
{
@@ -70,15 +70,17 @@ static PyObject *decode(PyObject *self, PyObject *args)
7070
if (territoryname) {
7171
territorycode = convertTerritoryIsoNameToCode(territoryname, 0);
7272
if (territorycode < 0) {
73-
return Py_False;
73+
latitude = NAN;
74+
longitude = NAN;
75+
return Py_BuildValue("ff", latitude, longitude);
7476
}
7577
} else
7678
territorycode = 0;
7779

7880
if (decodeMapcodeToLatLon(&latitude, &longitude, mapcode, territorycode)) {
79-
/* return 999/999 as error values */
80-
latitude = 999;
81-
longitude = 999;
81+
/* return nan,nan as error values */
82+
latitude = NAN;
83+
longitude = NAN;
8284
}
8385
return Py_BuildValue("ff", latitude, longitude);
8486
}

0 commit comments

Comments
 (0)