From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1CD5E394D8CA; Sat, 9 Apr 2022 10:23:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1CD5E394D8CA From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libquadmath/105101] incorrect rounding for sqrtq Date: Sat, 09 Apr 2022 10:23:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libquadmath X-Bugzilla-Version: unknown X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub 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: --- 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Apr 2022 10:23:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105101 --- Comment #6 from Jakub Jelinek --- (In reply to Thomas Koenig from comment #5) > There is another, much worse, problem, reported and analyzed by "Michael = S" > on comp.arch. The code has >=20 > #ifdef HAVE_SQRTL > { > long double xl =3D (long double) x; > if (xl <=3D LDBL_MAX && xl >=3D LDBL_MIN) > { > /* Use long double result as starting point. */ > y =3D (__float128) sqrtl (xl); >=20 > /* One Newton iteration. */ > y -=3D 0.5q * (y - x / y); > return y; > } > } > #endif >=20 > which assumes that long double has a higher precision than > normal double. On x86_64, this depends o the settings of the > FPU flags, so a number like 0x1.06bc82f7b9d71dfcbddf2358a0eap-1024=20 > is corrected with 32 ULP of error because there is only a single > round of Newton iterations if the FPU flags are set to normal precision. That is only a problem on OSes that do that, I think mainly BSDs, no? On Linux it should be fine (well, still not 0.5ulp precise, but not as bad = as when sqrtl is just double precision precise).=