From: Corinna Vinschen <vinschen@redhat.com>
To: newlib@sourceware.org
Subject: Re: [PATCH] Fix for k_tan.c specific inputs
Date: Wed, 18 Mar 2020 10:06:38 +0100 [thread overview]
Message-ID: <20200318090638.GA778468@calimero.vinschen.de> (raw)
In-Reply-To: <20200317144844.1075-1-fabian.schriever@gtd-gmbh.de>
[-- Attachment #1: Type: text/plain, Size: 2225 bytes --]
On Mar 17 15:48, Fabian Schriever wrote:
> This fix for k_tan.c is a copy from fdlibm version 5.3 (see also
> http://www.netlib.org/fdlibm/readme), adjusted to use the macros
> available in newlib (SET_LOW_WORD).
>
> This fix reduces the ULP error of the value shown in the fdlibm readme
> (tan(1.7765241907548024E+269)) to 0.45 (thereby reducing the error by
> 1).
>
> This issue only happens for large numbers that get reduced by the range
> reduction to a value smaller in magnitude than 2^-28, that is also
> reduced an uneven number of times. This seems rather unlikely given that
> one ULP is (much) larger than 2^-28 for the values that may cause an
> issue. Although given the sheer number of values a double can
> represent, it is still possible that there are more affected values,
> finding them however will be quite hard, if not impossible.
>
> We also took a look at how another library (libm in FreeBSD) handles the
> issue: In FreeBSD the complete if branch which checks for values smaller
> than 2^-28 (or rather 2^-27, another change done by FreeBSD) is moved
> out of the kernel function and into the external function. This means
> that the value that gets checked for this condition is the unreduced
> value. Therefore the input value which caused a problem in the
> fdlibm/newlib kernel tan will run through the full polynomial, including
> the careful calculation of -1/(x+r). So the difference is really whether
> r or y is used. r = y + p with p being the result of the polynomial with
> 1/3*x^3 being the largest (and magnitude defining) value. With x being
> <2^-27 we therefore know that p is smaller than y (y has to be at least
> the size of the value of x last mantissa bit divided by 2, which is at
> least x*2^-51 for doubles) by enough to warrant saying that r ~ y. So
> we can conclude that the general implementation of this special case is
> the same, FreeBSD simply has a different philosophy on when to handle
> especially small numbers.
> ---
> newlib/libm/math/k_tan.c | 29 +++++++++++++++++++++--------
> 1 file changed, 21 insertions(+), 8 deletions(-)
Pushed.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2020-03-18 9:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-17 14:48 Fabian Schriever
2020-03-18 9:06 ` Corinna Vinschen [this message]
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=20200318090638.GA778468@calimero.vinschen.de \
--to=vinschen@redhat.com \
--cc=newlib@sourceware.org \
/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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).