From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5617 invoked by alias); 27 Feb 2012 15:41:35 -0000 Received: (qmail 5608 invoked by uid 22791); 27 Feb 2012 15:41:33 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO sourceware.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 27 Feb 2012 15:41:20 +0000 From: "vincent-srcware at vinc17 dot net" To: glibc-bugs@sources.redhat.com Subject: [Bug math/706] pow() produces inaccurate results for base ~ 1.0, and large exponent on 32-bit x86 Date: Mon, 27 Feb 2012 15:41:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: math X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-srcware at vinc17 dot net X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2012-02/txt/msg00498.txt.bz2 http://sourceware.org/bugzilla/show_bug.cgi?id=3D706 --- Comment #10 from Vincent Lef=C3=A8vre 2012-02-27 15:40:08 UTC --- (In reply to comment #9) > Created attachment 6245 [details] > C code with a better algorithm Note concerning your code: it assumes that char is signed. You should use i= nt for small integers, not char. > When the exponent is an integer, a fast exponentiation is used [...] This is not perfect (you still won't get a very accurate result), but certa= inly better than the current code (I haven't looked at it), which is apparently affected by a cancellation. Note that if you want to compute pow(x,y) where= y is not necessarily an integer, you can write y =3D yi + yf, where yi is an integer and |yf| < 1 (e.g. |yf| <=3D 0.5 or 0 <=3D yf < 1). Then mathematic= ally, pow(x,y) =3D pow(pow(x,yi),yf), and you can use that to get a more accurate result than the current algorithm (I haven't checked in detail...). For more accurate algorithms concerning the integer powers: @Article{KLLLM2009a, AUTHOR =3D {P. Kornerup and Ch. Lauter and V. Lef=C3=A8vre= and N. Louvet and J.-M. Muller}, TITLE =3D {Computing Correctly Rounded Integer Powers in Floating-Point Arithmetic}, JOURNAL =3D {{ACM} Transactions on Mathematical Software}, VOLUME =3D {37}, NUMBER =3D {1}, MONTH =3D jan, YEAR =3D {2010}, URL =3D {http://doi.acm.org/10.1145/1644001.1644005}, DOI =3D {10.1145/1644001.1644005} } and for correct rounding of the general pow() function, assuming you already have an accurate algorithm: @Article{LauLef2009a, AUTHOR =3D {Ch. Lauter and V. Lef=C3=A8vre}, TITLE =3D {An efficient rounding boundary test for \texttt{pow(x,y)} in double precision}, JOURNAL =3D {{IEEE} Transactions on Computers}, PUBLISHER =3D {{IEEE} Computer Society Press, Los Alamitos, C= A}, VOLUME =3D {58}, NUMBER =3D {2}, PAGES =3D {197--207}, MONTH =3D feb, YEAR =3D {2009}, KEYWORDS =3D {floating-point arithmetic,correct rounding,pow= er function}, URL =3D {http://www.vinc17.net/research/papers/ieeetc2009-powr.pdf}, DOI =3D {10.1109/TC.2008.202} } --=20 Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=3Demail ------- You are receiving this mail because: ------- You are on the CC list for the bug.