Prevent dist calculation overflow
This commit is contained in:
@@ -355,11 +355,11 @@ void TelemetryItem::eval(const TelemetrySensor & sensor)
|
||||
}
|
||||
}
|
||||
uint32_t angle = abs(gpsItem.gps.latitude - gpsItem.pilotLatitude);
|
||||
uint32_t dist = (EARTH_RADIUS * M_PI / 180) * angle / 1000000;
|
||||
uint32_t dist = ((uint64_t )EARTH_RADIUS * M_PI / 180) * angle) / 1000000;
|
||||
uint32_t result = dist * dist;
|
||||
|
||||
angle = abs(gpsItem.gps.longitude - gpsItem.pilotLongitude);
|
||||
dist = gpsItem.distFromEarthAxis * angle / 1000000;
|
||||
dist = ((uint64_t ) gpsItem.distFromEarthAxis * angle) / 1000000;
|
||||
result += dist * dist;
|
||||
|
||||
// Length on ground (ignoring curvature of the earth)
|
||||
|
||||
Reference in New Issue
Block a user