From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A9FD83858D3C; Sat, 2 Mar 2024 15:52:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9FD83858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709394723; bh=cDnaVegSS1gY5mOJNwW1yefuqVbRiMy6YHdT3ChuM3U=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ln2hH+8ToSsrQuc3TdgLh/i/sisoKbY8Mio/bRLrEFSHrBXjU2oXMSpZNjVOEs0Yg 75j19OIGYp6MV9ihdGS4k7FwdCFnl6jeiK/q8MGLS5nErCn32NV53Jpv3jJ6N8CSlE mgGL4ouSjwz3yHEhbOLgpf6SxBpoWj6mXQTH5gi0= From: "g.peterhoff@t-online.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/77776] C++17 std::hypot implementation is poor Date: Sat, 02 Mar 2024 15:52:01 +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: 7.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: g.peterhoff@t-online.de X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: emsr at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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=3D77776 --- Comment #13 from g.peterhoff@t-online.de --- Thanks for the suggestions: template constexpr _Tp __hypot3(_Tp __x, _Tp __y, _Tp __z) noexcept { if (std::isinf(__x) | std::isinf(__y) | std::isinf(__z)) [[__unlikely__]] return _Tp(INFINITY); __x =3D std::fabs(__x); __y =3D std::fabs(__y); __z =3D std::fabs(__z); const _Tp __max =3D std::fmax(std::fmax(__x, __y), __z); if (__max =3D=3D _Tp{}) [[__unlikely__]] return __max; __x /=3D __max; __y /=3D __max; __z /=3D __max; return std::sqrt(__x*__x + __y*__y + __z*__z) * __max; } The functions are then set to constexpr/noexcept. regards Gero=