From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/651 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: correctly rounded sqrt Date: Thu, 15 Mar 2012 02:46:48 +0100 Message-ID: <20120315014647.GI5728@port70.net> References: <20120314165604.GF5728@port70.net> <20120314190123.GH5728@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="B8ONY/mu/bqBak9m" X-Trace: dough.gmane.org 1331776024 4087 80.91.229.3 (15 Mar 2012 01:47:04 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 15 Mar 2012 01:47:04 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-652-gllmg-musl=m.gmane.org@lists.openwall.com Thu Mar 15 02:47:03 2012 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1S7zmO-0007kx-Pj for gllmg-musl@plane.gmane.org; Thu, 15 Mar 2012 02:47:00 +0100 Original-Received: (qmail 30053 invoked by uid 550); 15 Mar 2012 01:47:00 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 30045 invoked from network); 15 Mar 2012 01:47:00 -0000 Content-Disposition: inline In-Reply-To: <20120314190123.GH5728@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:651 Archived-At: --B8ONY/mu/bqBak9m Content-Type: text/plain; charset=us-ascii Content-Disposition: inline * Szabolcs Nagy [2012-03-14 20:01:23 +0100]: > * Szabolcs Nagy [2012-03-14 17:56:05 +0100]: > > i tried to solve the sqrt issue with a wrapper ok as discussed a simpler and better solution without precision setting etc in c --B8ONY/mu/bqBak9m Content-Type: text/x-csrc; charset=us-ascii Content-Disposition: attachment; filename="x_sqrt.c" #include #include /* dekker exact mult u*u == hi + lo */ static void sq(long double *hi, long double *lo, long double u) { static const long double c = 1.0 + 0x1p33; long double cu, u1, u2; cu = c*u; u1 = (u - cu) + cu; u2 = u - u1; *hi = u*u; *lo = (u1*u1 - *hi) + u1*u2*2.0 + u2*u2; } /* correctly rounded double sqrt using long double arithmetics for x87 */ double x_sqrt(double x) { union { long double x; struct{ uint64_t m; uint16_t es; uint16_t pad; } bits; } u; long double r, hi, lo; u.x = sqrtl(x); if ((u.bits.m&0x7ff) == 0x400) { if ((u.bits.es&0x7fff) == 0x7fff) return u.x; sq(&hi, &lo, u.x); r = x - hi - lo; if (r > 0) u.bits.m++; else u.bits.m--; return u.x; } return u.x; } --B8ONY/mu/bqBak9m--