diff options
| author | Keith Packard <keithp@keithp.com> | 2014-06-05 18:31:06 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2014-06-05 18:31:06 -0700 | 
| commit | d7df6e8c47df35c0d27f1a2559ecc305ef28d271 (patch) | |
| tree | f1fda972e2337087ebedddab27550d27d852758c /src/kernel/ao_distance.c | |
| parent | 2db2b75f8847ca0066bb19771653a65c9098ae52 (diff) | |
altos: ao_distance was overflowing when checking for longitude wrap
Need to shift everyone right one bit to fit in 32 bits
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/kernel/ao_distance.c')
| -rw-r--r-- | src/kernel/ao_distance.c | 3 | 
1 files changed, 2 insertions, 1 deletions
| diff --git a/src/kernel/ao_distance.c b/src/kernel/ao_distance.c index ba7d59fe..5654182a 100644 --- a/src/kernel/ao_distance.c +++ b/src/kernel/ao_distance.c @@ -24,6 +24,7 @@ ao_dist(int32_t a, int32_t b)  	int32_t	d = a - b;  	if (d < 0)  		d = -d; +  	return (uint32_t) ((int64_t) d * 111198 / 10000000);  } @@ -98,7 +99,7 @@ ao_lon_dist(int32_t lon_a, int32_t lon_b)  	uint32_t	lon_dist;  	/* check if it's shorter to go the other way around */ -	if (lon_a < lon_b - 1800000000) +	if ((lon_a >> 1) < (lon_b >> 1) - (1800000000 >> 1))  		lon_a += 3600000000;  	lon_dist = ao_dist(lon_a, lon_b);  	if (c) { | 
