From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: Conformance issues to address after 0.9.12 release
Date: Mon, 29 Jul 2013 18:00:46 +0200 [thread overview]
Message-ID: <20130729160046.GC25714@port70.net> (raw)
In-Reply-To: <20130729063456.GA31564@brightrain.aerifal.cx>
* Rich Felker <dalias@aerifal.cx> [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
next prev parent reply other threads:[~2013-07-29 16:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-29 6:34 Rich Felker
2013-07-29 16:00 ` Szabolcs Nagy [this message]
2013-07-29 21:04 ` Rich Felker
2013-07-30 2:26 ` Szabolcs Nagy
2013-08-12 19:27 ` Szabolcs Nagy
2013-08-13 3:32 ` Rich Felker
2013-08-13 3:45 ` Szabolcs Nagy
2013-08-13 4:25 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130729160046.GC25714@port70.net \
--to=nsz@port70.net \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).