Skip to content

Commit 1251e56

Browse files
committed
[SYCL] [Test] Deal with nan and inf input in is_about_FP function in math_utils.hpp
Signed-off-by: haonanya <[email protected]>
1 parent e28efb4 commit 1251e56

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

sycl/test/devicelib/math_utils.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
// T must be float-point type
55
template <typename T>
66
bool is_about_FP(T x, T y) {
7-
if (x == y)
8-
return true;
7+
// At least one input is nan
8+
if (std::isnan(x) || std::isnan(y))
9+
return std::isnan(x) && std::isnan(y);
10+
// At least one input is inf
11+
else if (std::isinf(x) || std::isinf(y))
12+
return (x == y);
13+
// two finite
914
else {
1015
if (x != 0 && y != 0) {
1116
T max_v = std::fmax(std::abs(x), std::abs(y));
1217
return (std::abs(x - y) / max_v) <
13-
std::numeric_limits<T>::epsilon() * 100;
14-
}
15-
else {
18+
std::numeric_limits<T>::epsilon() * 100;
19+
} else {
1620
if (x != 0)
1721
return std::abs(x) < std::numeric_limits<T>::epsilon() * 100;
1822
else

0 commit comments

Comments
 (0)