Skip to content

Commit 82407be

Browse files
committed
abs now returns unsigned zero when input is a signed zero
1 parent 597cd4b commit 82407be

File tree

1 file changed

+5
-4
lines changed
  • dpctl/tensor/libtensor/include/kernels/elementwise_functions

1 file changed

+5
-4
lines changed

dpctl/tensor/libtensor/include/kernels/elementwise_functions/abs.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,16 @@ template <typename argT, typename resT> struct AbsFunctor
6565
{
6666

6767
if constexpr (std::is_same_v<argT, bool> ||
68-
(std::is_integral<argT>::value &&
69-
std::is_unsigned<argT>::value))
70-
{
68+
std::is_unsigned<argT>::value) {
7169
static_assert(std::is_same_v<resT, argT>);
7270
return x;
7371
}
74-
else {
72+
else if (std::is_integral<argT>::value || is_complex<argT>::value) {
7573
return std::abs(x);
7674
}
75+
else {
76+
return (x == argT(0)) ? resT(0) : resT(std::abs(x));
77+
}
7778
}
7879
};
7980

0 commit comments

Comments
 (0)