Skip to content

Commit 8cd6672

Browse files
committed
apply suggestions
Signed-off-by: Sidorov, Dmitry <[email protected]>
1 parent 20068a6 commit 8cd6672

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

sycl/test-e2e/DeviceLib/built-ins/offload-prec-div-sqrt.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
// Test if div and sqrt become precise from IEEE-754 perspective when
55
// -foffload-fp32-prec-div -foffload-fp32-prec-sqrt are passed.
66

7+
#include <bit>
78
#include <cmath>
89
#include <sycl/detail/core.hpp>
910
#include <sycl/usm.hpp>
1011

1112
constexpr float value = 560.0f;
12-
constexpr float divider = 280.0f;
13+
constexpr float divider = 279.9f;
1314

14-
int32_t ulp_difference(float lhs, float rhs) {
15-
int32_t lhsInt = *reinterpret_cast<int32_t *>(&lhs);
16-
int32_t rhsInt = *reinterpret_cast<int32_t *>(&rhs);
15+
int32_t ulp_distance(float lhs, float rhs) {
16+
int32_t lhsInt = std::bit_cast<int32_t>(lhs);
17+
int32_t rhsInt = std::bit_cast<int32_t>(rhs);
1718

1819
return std::abs(lhsInt - rhsInt);
1920
}
@@ -33,8 +34,8 @@ void test_div() {
3334
}).wait();
3435

3536
float hostRef = value / divider;
36-
int ulpDiff = ulp_difference(hostRef, *output);
37-
assert(std::abs(ulpDiff) < 1 && "Division is not precise");
37+
int ulpDist = ulp_distance(hostRef, *output);
38+
assert(ulpDist == 0 && "Division is not precise");
3839
}
3940

4041
void test_sqrt() {
@@ -50,8 +51,8 @@ void test_sqrt() {
5051
}).wait();
5152

5253
float hostRef = std::sqrt(value);
53-
int ulpDiff = ulp_difference(hostRef, *output);
54-
assert(std::abs(ulpDiff) < 1 && "Sqrt is not precise");
54+
int ulpDist = ulp_distance(hostRef, *output);
55+
assert(ulpDist == 0 && "Sqrt is not precise");
5556
}
5657

5758
int main() {

0 commit comments

Comments
 (0)