From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/3769 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: Conformance issues to address after 0.9.12 release Date: Mon, 29 Jul 2013 18:00:46 +0200 Message-ID: <20130729160046.GC25714@port70.net> References: <20130729063456.GA31564@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1375113657 27927 80.91.229.3 (29 Jul 2013 16:00:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 29 Jul 2013 16:00:57 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-3773-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jul 29 18:01:00 2013 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 1V3psZ-00044V-JT for gllmg-musl@plane.gmane.org; Mon, 29 Jul 2013 18:00:59 +0200 Original-Received: (qmail 9245 invoked by uid 550); 29 Jul 2013 16:00:58 -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 9236 invoked from network); 29 Jul 2013 16:00:58 -0000 Content-Disposition: inline In-Reply-To: <20130729063456.GA31564@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:3769 Archived-At: * Rich Felker [2013-07-29 02:34:56 -0400]: > - i387 math asm does not truncate excess precision. Whether or not > this omission is conforming in terms of the return value, it results > in lost underflow exceptions, as demonstrated by nsz's math tests. the underflow problem is not i387 or excess precision related: many (odd) math functions are almost the identity function around x==0 (sin,asin,tan,atan,sinh,atanh,..) in those cases the traditional implementation is if (fabs(x) < thres) return x; if (fabs(x) < thres2) return x + C*x*x*x; ... (in case of double precision thres is usually around 0x1p-27 so |x|*0x1p-54 > |C*x*x*x|) (note that nan should be checked first and the thresholds are usually checked on the bit representation with int airthmetics) so for subnormal results x is returned: no exception is raised (underflow and inexact should be raised if x!=0 since the result is just an approximation) one might think that the first check is useless optimization, but if the C*x*x*x part is always calculated then underflow is raised even if x is nowhere near subnormal (eg x == 0x1p-500) a correct solution is if (fabs(x) < thres) { if (fabs(x) < 0x1p-1022) FORCE_EVAL(x * 1e-100); // raise inexact and underflow if x!=0 else FORCE_EVAL(x + 1e100); // raise inexact return x; } if (fabs(x) < thres2) { FORCE_EVAL(x + 1e-100); // raise inexact (may be omitted) return x + C*x*x*x; } which is ugly code bloat because volatile load/store is not optimized in FORCE_EVAL by gcc i387 is usually problematic in the second part: x + C*x*x*x may not raise inexact if x is float and FLT_EVAL_METHOD==2 so the extra FORCE_EVAL or equivalent is needed