File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,9 @@ template <typename T> inline T __atan2pi(T x, T y) {
36
36
return std::atan2 (x, y) / M_PI;
37
37
}
38
38
39
- template <typename T> inline T __cospi (T x) { return std::cos (M_PI * x); }
39
+ template <typename T> inline T __cospi (T x) {
40
+ return std::sin (M_PI * (0.5 - x));
41
+ }
40
42
41
43
template <typename T> T inline __fract (T x, T *iptr) {
42
44
T f = std::floor (x);
Original file line number Diff line number Diff line change
1
+ // RUN: %{build} -o %t.out
2
+ // RUN: %{run} %t.out
3
+
4
+ #include < iomanip>
5
+ #include < iostream>
6
+ #include < sycl.hpp>
7
+
8
+ template <typename T> T get_ulp_std (T x) {
9
+ const T inf = std::numeric_limits<T>::infinity ();
10
+ const T negative = std::fabs (std::nextafter (x, -inf) - x);
11
+ const T positive = std::fabs (std::nextafter (x, inf) - x);
12
+ return std::fmin (negative, positive);
13
+ }
14
+
15
+ void testCospi () {
16
+ const double value = 0.4863334355 ; // some random value
17
+ const double reference =
18
+ 0.042921588887841428949787569990803604014217853546142578125 ; // calculated
19
+ // with
20
+ // oclmath
21
+ const unsigned int ulpsExpected =
22
+ 4 ; // according to section 4.17.5 of the SYCL 2020 spec, math functions
23
+ // correspond to those from OpenCL 1.2 spec, so this accuracy comes
24
+ // from the OpenCL 1.2 spec
25
+ const double differenceExpected = ulpsExpected * get_ulp_std (reference);
26
+ const double hostDifference = std::fabs (sycl::cospi (value) - reference);
27
+
28
+ std::cout << std::setprecision (17 ) << " cospi: " << ' \n '
29
+ << " ref:\t " << reference << ' \n '
30
+ << " host:\t " << sycl::cospi (value) << ' \n '
31
+ << " diff host:\t " << hostDifference << ' \n '
32
+ << " expected:\t " << differenceExpected << std::endl;
33
+
34
+ assert (hostDifference <= differenceExpected && " Host result incorrect" );
35
+ }
36
+
37
+ int main () {
38
+ testCospi ();
39
+ return 0 ;
40
+ }
You can’t perform that action at this time.
0 commit comments