From 626b2fb8286745d4bd6b0d634bdb173c0c4bcb12 Mon Sep 17 00:00:00 2001 From: Junzi Sun Date: Mon, 21 Sep 2015 16:46:54 +0200 Subject: [PATCH] fix zero division error --- decoder.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/decoder.py b/decoder.py index d759a1f..941d50f 100644 --- a/decoder.py +++ b/decoder.py @@ -238,14 +238,18 @@ def get_callsign(msg): return cs -def cprN(lat, isodd): - nl = cprNL(lat) - isodd +def cprN(lat, is_odd): + nl = cprNL(lat) - is_odd return nl if nl > 1 else 1 def cprNL(lat): - nz = 60 - a = 1 - math.cos(math.pi * 2 / nz) - b = math.cos(math.pi / 180.0 * abs(lat)) ** 2 - nl = 2 * math.pi / (math.acos(1 - a/b)) - return int(nl) + try: + nz = 60 + a = 1 - math.cos(math.pi * 2 / nz) + b = math.cos(math.pi / 180.0 * abs(lat)) ** 2 + nl = 2 * math.pi / (math.acos(1 - a/b)) + return int(nl) + except: + # happens when latitude is +/-90 degree + return 1