Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sycl/include/sycl/stl_wrappers/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@
#include <sycl/detail/defines_elementary.hpp>

#ifdef __SYCL_DEVICE_ONLY__
// std::nan is an outlier with its string argument. We can't simply link to it.
// Instead, we redefine both std::nan and sycl::nan as a macro.
// NaN values are NEVER equal, so the actual value doesn't matter.
// This is quite kludgy, and it means that nan() is not composable, but it's
// not like anyone is doing that. Forgiveness is easier to get than permission.
namespace std {
constexpr double NanAbuse = std::numeric_limits<double>::quiet_NaN();
}
namespace sycl {
constexpr double NanAbuse = std::numeric_limits<double>::quiet_NaN();
}

#define nan(x) NanAbuse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's acceptable. NaN value must be as specified in the string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No two NaNs are ever equal. Even std::nan("1") and std::nan("1") so it doesn't matter what the value is, so long as it is NaN. In practice, supposedly some people can use the strings to disambiguate NaN values in the debugger, to help understand their provenance, but this is entirely outside the scope.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is always std::bit_cast...


extern "C" {
extern __DPCPP_SYCL_EXTERNAL int abs(int x);
extern __DPCPP_SYCL_EXTERNAL long int labs(long int x);
Expand Down
Loading