From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 121023858C52; Wed, 9 Nov 2022 13:29:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 121023858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668000549; bh=343qgLPT7xz1Fjp4VgmEL4l2Qq2xUSI7oRzd+/bIV3A=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PWLemAIw6p0xY1ovSjFA5+WuqLCVovNK6B2PVX7vlLy6Q7Gmg+/SGYP2MQwjiYKEj T+Sqe//sqHdX8ixbrZUjfKwGYejr/NTuGhE/Mh38s5qPaeCZe4BWZRYaT0kvMqzIVC Hh8uq2LIuDNy2CXv0US1zVDRY2vAD8fmiAqOAWM8= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/107538] std::pow(10, std::complex(NaN, 1)) aborts with -D_GLIBCXX_ASSERTIONS Date: Wed, 09 Nov 2022 13:29:07 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107538 --- Comment #3 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #0) > #define _GLIBCXX_ASSERTIONS > #include > #include >=20 > int main() > { > double nan =3D std::numeric_limits::quiet_NaN(); > std::pow(10, std::complex(nan, 1)); Actually maybe the assertion is OK. This violates [complex.numbers] p3: "If the result of a function is not mathematically defined or not in the ra= nge of representable values for its type, the behavior is undefined." 10^(nan + 1i) is not mathematically defined, an assertion seems OK. If we want to prevent the assertion here we could do: --- a/libstdc++-v3/include/std/complex +++ b/libstdc++-v3/include/std/complex @@ -699,12 +699,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION && !_GLIBCXX_FAST_MATH>::_S_do_it(__z); } + template + inline complex<_Tp> + __polar(const _Tp& __rho, const _Tp& __theta) + { return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta)); } + template inline complex<_Tp> polar(const _Tp& __rho, const _Tp& __theta) { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2459. std::polar should require a non-negative rho __glibcxx_assert( __rho >=3D 0 ); - return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta)); + return std::__polar<_Tp>(__rho, __theta); } template @@ -778,7 +785,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template inline complex<_Tp> __complex_exp(const complex<_Tp>& __z) - { return std::polar<_Tp>(exp(__z.real()), __z.imag()); } + { return std::__polar<_Tp>(exp(__z.real()), __z.imag()); } #if _GLIBCXX_USE_C99_COMPLEX inline __complex__ float @@ -1038,7 +1045,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return pow(__x.real(), __y); complex<_Tp> __t =3D std::log(__x); - return std::polar<_Tp>(exp(__y * __t.real()), __y * __t.imag()); + return std::__polar<_Tp>(exp(__y * __t.real()), __y * __t.imag()); } template @@ -1075,8 +1082,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline complex<_Tp> pow(const _Tp& __x, const complex<_Tp>& __y) { - return __x > _Tp() ? std::polar<_Tp>(pow(__x, __y.real()), - __y.imag() * log(__x)) + return __x > _Tp() ? std::__polar<_Tp>(pow(__x, __y.real()), + __y.imag() * log(__x)) : std::pow(complex<_Tp>(__x), __y); }=