Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Sidorov, Dmitry <[email protected]>
  • Loading branch information
MrSidims committed Feb 20, 2025
1 parent 20068a6 commit b5b7681
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions sycl/test-e2e/DeviceLib/built-ins/offload-prec-div-sqrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
// Test if div and sqrt become precise from IEEE-754 perspective when
// -foffload-fp32-prec-div -foffload-fp32-prec-sqrt are passed.

#include <bit>
#include <cmath>
#include <sycl/detail/core.hpp>
#include <sycl/usm.hpp>

constexpr float value = 560.0f;
constexpr float divider = 280.0f;
constexpr float divider = 279.9f;

int32_t ulp_difference(float lhs, float rhs) {
int32_t lhsInt = *reinterpret_cast<int32_t *>(&lhs);
int32_t rhsInt = *reinterpret_cast<int32_t *>(&rhs);
int32_t ulp_distance(float lhs, float rhs) {
int32_t lhsInt = std::bit_cast<int32_t>(lhs);
int32_t rhsInt = std::bit_cast<int32_t>(rhs);

return std::abs(lhsInt - rhsInt);
}
Expand All @@ -34,7 +35,7 @@ void test_div() {

float hostRef = value / divider;
int ulpDiff = ulp_difference(hostRef, *output);
assert(std::abs(ulpDiff) < 1 && "Division is not precise");
assert(ulpDiff == 0 && "Division is not precise");
}

void test_sqrt() {
Expand All @@ -51,7 +52,7 @@ void test_sqrt() {

float hostRef = std::sqrt(value);
int ulpDiff = ulp_difference(hostRef, *output);
assert(std::abs(ulpDiff) < 1 && "Sqrt is not precise");
assert(ulpDiff == 0 && "Sqrt is not precise");
}

int main() {
Expand Down

0 comments on commit b5b7681

Please sign in to comment.