Skip to content

Commit

Permalink
Closes gh-1278
Browse files Browse the repository at this point in the history
Provides an alternative implementation of std::abs for complex types
via std::hypot which is used on Windows.
  • Loading branch information
oleksandr-pavlyk committed Aug 13, 2023
1 parent 50f1074 commit 345fdaa
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once
#include <CL/sycl.hpp>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <type_traits>
Expand Down Expand Up @@ -72,9 +73,25 @@ template <typename argT, typename resT> struct AbsFunctor
return x;
}
else {
return std::abs(x);
if constexpr (is_complex<argT>::value) {
return cabs(x);
}
else {
return std::abs(x);
}
}
}

private:
template <typename realT> realT cabs(std::complex<realT> const &z)
{
#ifdef _WINDOWS
// work-around for gh-1279
return std::hypot(std::real(z), std::imag(z));
#else
return std::abs(z);
#endif
}
};

template <typename argT,
Expand Down

0 comments on commit 345fdaa

Please sign in to comment.