Skip to content

Commit

Permalink
Resolves gh-1439
Browse files Browse the repository at this point in the history
Adjusts logic in expm1 and sin for negative 0s inputs in real and complex cases
  • Loading branch information
ndgrigorian committed Nov 26, 2023
1 parent 5ec9fd5 commit 1c4b0ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,22 @@ template <typename argT, typename resT> struct Expm1Functor
}

// x, y finite numbers
realT cosY_val;
auto cosY_val_multi_ptr = sycl::address_space_cast<
sycl::access::address_space::private_space,
sycl::access::decorated::yes>(&cosY_val);
const realT sinY_val = sycl::sincos(y, cosY_val_multi_ptr);
const realT sinhalfY_val = std::sin(y / 2);
const realT cosY_val = std::cos(y);
const realT sinY_val = (y == 0) ? y : std::sin(y);
const realT sinhalfY_val = (y == 0) ? y : std::sin(y / 2);

const realT res_re =
std::expm1(x) * cosY_val - 2 * sinhalfY_val * sinhalfY_val;
const realT res_im = std::exp(x) * sinY_val;
realT res_im = std::exp(x) * sinY_val;
return resT{res_re, res_im};
}
else {
static_assert(std::is_floating_point_v<argT> ||
std::is_same_v<argT, sycl::half>);
static_assert(std::is_same_v<argT, resT>);
if (in == 0) {
return in;
}
return std::expm1(in);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ template <typename argT, typename resT> struct SinFunctor
*/
if (in_re_finite && in_im_finite) {
#ifdef USE_SYCL_FOR_COMPLEX_TYPES
return exprm_ns::sin(
resT res = exprm_ns::sin(
exprm_ns::complex<realT>(in)); // std::sin(in);
#else
return std::sin(in);
resT res = std::sin(in);
#endif
if (in_re == realT(0)) {
res.real(std::copysign(realT(0), in_re));
}
return res;
}

/*
Expand Down Expand Up @@ -176,8 +180,10 @@ template <typename argT, typename resT> struct SinFunctor
return resT{sinh_im, -sinh_re};
}
else {
static_assert(std::is_floating_point_v<argT> ||
std::is_same_v<argT, sycl::half>);
static_assert(std::is_same_v<argT, resT>);
if (in == 0) {
return in;
}
return std::sin(in);
}
}
Expand Down

0 comments on commit 1c4b0ab

Please sign in to comment.