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
1112constexpr 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
4041void 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
5758int main () {
0 commit comments