Skip to content

Commit ea464f5

Browse files
committed
Handled a corner case with abs(MIN_INT)
1 parent 4582bcf commit ea464f5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

dpnp/backend/kernels/dpnp_krnl_logic.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,15 @@ static sycl::event dpnp_allclose(sycl::queue &q,
174174
continue;
175175
}
176176
}
177-
partial &= (std::abs(array1[i] - array2[i]) <=
178-
(atol_val + rtol_val * std::abs(array2[i])));
177+
178+
// casting integeral to floating type to avoid bad behavior
179+
// on abs(MIN_INT), which leads to undefined result
180+
using _Arr2Type = std::conditional_t<std::is_integral_v<_DataType2>,
181+
_TolType, _DataType2>;
182+
_Arr2Type arr2 = static_cast<_Arr2Type>(array2[i]);
183+
184+
partial &= (std::abs(array1[i] - arr2) <=
185+
(atol_val + rtol_val * std::abs(arr2)));
179186
}
180187
partial = sycl::all_of_group(gr, partial);
181188

0 commit comments

Comments
 (0)