Skip to content

Commit 1a6ee14

Browse files
authored
[SYCL] Fix acos edge case (#14026)
1 parent 2e212e0 commit 1a6ee14

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

libdevice/fallback-complex-fp64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ double __complex__ __devicelib_cacos(double __complex__ z) {
311311
return CMPLX(z_real, -z_imag);
312312
return CMPLX(z_real, z_real);
313313
}
314-
if (__spirv_IsInf(z_real))
315-
return CMPLX(__pi / 2.0, -z_real);
314+
if (__spirv_IsInf(z_imag))
315+
return CMPLX(__pi / 2.0, -z_imag);
316316
if (z_real == 0 && (z_imag == 0 || __spirv_IsNan(z_imag)))
317317
return CMPLX(__pi / 2.0, -z_imag);
318318
double __complex__ w =

sycl/test-e2e/Regression/acos.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// REQUIRES: aspect-fp64
2+
// UNSUPPORTED: cuda || hip
3+
4+
// RUN: %{build} -o %t.out
5+
// RUN: %{run} %t.out
6+
#include <complex>
7+
#include <sycl/detail/core.hpp>
8+
#include <sycl/usm.hpp>
9+
10+
using namespace sycl;
11+
using T = std::complex<double>;
12+
13+
int main() {
14+
queue q;
15+
const double pi = std::atan2(+0., -0.);
16+
T data[][2] = {{{-2, -INFINITY}, {pi / 2, INFINITY}},
17+
{{-0., INFINITY}, {pi / 2, -INFINITY}}};
18+
int N = std::size(data);
19+
auto *p = malloc_shared<T>(N, q);
20+
21+
q.single_task([=] {
22+
for (int i = 0; i < N; ++i) {
23+
p[i] = std::acos(data[i][0]);
24+
}
25+
}).wait();
26+
27+
int fails = 0;
28+
for (int i = 0; i < N; ++i) {
29+
auto actual = p[i];
30+
auto expected = data[i][1];
31+
if (expected != actual) {
32+
std::cout << i << " fail:"
33+
<< "expected = " << expected << ", actual = " << actual << "\n";
34+
++fails;
35+
}
36+
}
37+
38+
return fails;
39+
}

0 commit comments

Comments
 (0)