4
4
// Test if div and sqrt become precise from IEEE-754 perspective when
5
5
// -foffload-fp32-prec-div -foffload-fp32-prec-sqrt are passed.
6
6
7
+ #include < bit>
7
8
#include < cmath>
8
9
#include < sycl/detail/core.hpp>
9
10
#include < sycl/usm.hpp>
10
11
11
12
constexpr float value = 560 .0f ;
12
- constexpr float divider = 280 . 0f ;
13
+ constexpr float divider = 279 . 9f ;
13
14
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);
17
18
18
19
return std::abs (lhsInt - rhsInt);
19
20
}
@@ -33,8 +34,8 @@ void test_div() {
33
34
}).wait ();
34
35
35
36
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" );
38
39
}
39
40
40
41
void test_sqrt () {
@@ -50,8 +51,8 @@ void test_sqrt() {
50
51
}).wait ();
51
52
52
53
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" );
55
56
}
56
57
57
58
int main () {
0 commit comments