From owner-freebsd-numerics@freebsd.org Wed May 8 20:24:35 2019 Return-Path: Delivered-To: freebsd-numerics@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0EB551592D41 for ; Wed, 8 May 2019 20:24:35 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 817178D6E9 for ; Wed, 8 May 2019 20:24:34 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: by mailman.ysv.freebsd.org (Postfix) id 41DA41592D40; Wed, 8 May 2019 20:24:34 +0000 (UTC) Delivered-To: numerics@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1DFB01592D3F for ; Wed, 8 May 2019 20:24:34 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.ysv.freebsd.org (mxrelay.ysv.freebsd.org [IPv6:2001:1900:2254:206a::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.ysv.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AD04F8D6E6 for ; Wed, 8 May 2019 20:24:33 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.ysv.freebsd.org (Postfix) with ESMTPS id E3EF2B61F for ; Wed, 8 May 2019 20:24:32 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id x48KOWWN008470 for ; Wed, 8 May 2019 20:24:32 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id x48KOWPv008468 for numerics@FreeBSD.org; Wed, 8 May 2019 20:24:32 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: numerics@FreeBSD.org Subject: [Bug 237800] pow(3) returns inaccurate results Date: Wed, 08 May 2019 20:24:32 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: misc X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Many People X-Bugzilla-Who: sgk@troutmask.apl.washington.edu X-Bugzilla-Status: Open X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: numerics@FreeBSD.org 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: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 May 2019 20:24:35 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D237800 --- Comment #5 from sgk@troutmask.apl.washington.edu --- (In reply to Peter Jeremy from comment #3) Peter, special casing small positive y values is still=20 fraught with floating rounding errors. Expanding on the toy program a bit. #include #include int main() { int n; double x, x2, x3, a, b; printf("%a\n", 1.e29); /* check printf */ printf("%a\n", pow(10, 29)); /* gcc constant-folds */ x =3D 10; printf("%a\n", pow(x, 29)); /* need library call */ x3 =3D x * x * x; /* x**3 */ a =3D x3 * x3 * x; /* x**7 */ a *=3D a; /* x**14 */ b =3D x * a * a; /* x**29 */ printf("%a\n", b); x2 =3D x * x; /* x**2 */ a =3D x2 * x2; /* x**4 */ b =3D a * a; /* x**8 */ b =3D x * b * b * b * a; printf("%a\n", b); x =3D frexp(x, &n); x2 =3D x * x; /* x**2 */ a =3D x2 * x2; /* x**4 */ a *=3D a; /* x**8 */ b =3D x * a * a * a * (x2 * x2); b =3D ldexp(b, n*29); printf("%a\n", b); } With clang, cc -o z a.c -lm && ./z 0x1.431e0fae6d721p+96 0x1.431e0fae6d722p+96 0x1.431e0fae6d722p+96 0x1.431e0fae6d721p+96 0x1.431e0fae6d722p+96 0x1.431e0fae6d722p+96 With top-of-tree GCC, ~/work/x/bin/gcc -o z a.c -lm && ./z 0x1.431e0fae6d721p+96 0x1.431e0fae6d721p+96 <-- constant-folding with mpfr 0x1.431e0fae6d722p+96 0x1.431e0fae6d721p+96 0x1.431e0fae6d722p+96 0x1.431e0fae6d722p+96 ~/work/x/bin/gcc -o z a.c -fno-builtin -lm && ./z 0x1.431e0fae6d721p+96 0x1.431e0fae6d722p+96 <-- libm pow() called 0x1.431e0fae6d722p+96 0x1.431e0fae6d721p+96 0x1.431e0fae6d722p+96 0x1.431e0fae6d722p+96 --=20 You are receiving this mail because: You are the assignee for the bug.=