Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libcxx] replaces sqrt(complex<T>) implementation with builtin #122391

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions libcxx/include/complex
Original file line number Diff line number Diff line change
Expand Up @@ -1059,16 +1059,15 @@ inline _LIBCPP_HIDE_FROM_ABI complex<_Tp> log10(const complex<_Tp>& __x) {

// sqrt

_LIBCPP_HIDE_FROM_ABI inline _Complex float __csqrt(_Complex float __v) { return __builtin_csqrtf(__v); }

_LIBCPP_HIDE_FROM_ABI inline _Complex double __csqrt(_Complex double __v) { return __builtin_csqrt(__v); }

_LIBCPP_HIDE_FROM_ABI inline _Complex long double __csqrt(_Complex long double __v) { return __builtin_csqrtl(__v); }

template <class _Tp>
_LIBCPP_HIDE_FROM_ABI complex<_Tp> sqrt(const complex<_Tp>& __x) {
if (std::isinf(__x.imag()))
return complex<_Tp>(_Tp(INFINITY), __x.imag());
if (std::isinf(__x.real())) {
if (__x.real() > _Tp(0))
return complex<_Tp>(__x.real(), std::isnan(__x.imag()) ? __x.imag() : std::copysign(_Tp(0), __x.imag()));
return complex<_Tp>(std::isnan(__x.imag()) ? __x.imag() : _Tp(0), std::copysign(__x.real(), __x.imag()));
}
return std::polar(std::sqrt(std::abs(__x)), std::arg(__x) / _Tp(2));
return complex<_Tp>(__from_builtin_tag(), std::__csqrt(__x.__builtin()));
}

// exp
Expand Down
Loading