Avoid UBSan report in greatCircleDistance

This commit is contained in:
Alexey Milovidov 2021-01-23 00:03:59 +03:00
parent 4afcb94a8a
commit 0528ca60d6
3 changed files with 8 additions and 1 deletions

View File

@ -160,6 +160,12 @@ DECLARE_MULTITARGET_CODE(
namespace
{
inline NO_SANITIZE_UNDEFINED size_t metricLUTIndex(float latitude_midpoint)
{
/// Implementation specific behaviour on overflow or infinite value.
return static_cast<size_t>(latitude_midpoint) & (METRIC_LUT_SIZE - 1);
}
template <Method method>
float distance(float lon1deg, float lat1deg, float lon2deg, float lat2deg)
{
@ -177,7 +183,7 @@ float distance(float lon1deg, float lat1deg, float lon2deg, float lat2deg)
/// But if longitude is close but latitude is different enough, there is no difference between meridian and great circle line.
float latitude_midpoint = (lat1deg + lat2deg + 180) * METRIC_LUT_SIZE / 360; // [-90, 90] degrees -> [0, KTABLE] indexes
size_t latitude_midpoint_index = static_cast<size_t>(latitude_midpoint) & (METRIC_LUT_SIZE - 1);
size_t latitude_midpoint_index = metricLUTIndex(latitude_midpoint);
/// This is linear interpolation between two table items at index "latitude_midpoint_index" and "latitude_midpoint_index + 1".

View File

@ -0,0 +1 @@
SELECT greatCircleAngle(0, -9223372036854775808, number, number) FROM numbers(3) FORMAT Null;