Date: Wed, 08 May 2019 20:24:32 +0000 From: bugzilla-noreply@freebsd.org To: numerics@FreeBSD.org Subject: [Bug 237800] pow(3) returns inaccurate results Message-ID: <bug-237800-18636-LLE1SJB0mw@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-237800-18636@https.bugs.freebsd.org/bugzilla/> References: <bug-237800-18636@https.bugs.freebsd.org/bugzilla/>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <stdio.h> #include <math.h> 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.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-237800-18636-LLE1SJB0mw>