mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [musl] casinh function accuracy problem
Date: Tue, 11 Feb 2020 23:19:12 -0500	[thread overview]
Message-ID: <20200212041912.GW1663@brightrain.aerifal.cx> (raw)
In-Reply-To: <alpine.LRH.2.02.2002121450170.16988@key0.esi.com.au>

On Wed, Feb 12, 2020 at 03:07:17PM +1100, Damian McGuckin wrote:
> On Tue, 11 Feb 2020, Rich Felker wrote:
> 
> >My minimal criterion for large-scale improvements of src/complex would
> >be fixing any remaining cases where inf/nan behavior is badly wrong or
> >there's catastrophic error (>2^52 ulp, or even just >2^20 ulp or so).
> >Beyond that, I think "reducing ulp error" would be nice but hard to
> >quantify and make a goal without having an idea how bad it is now, not
> >to mention without having rigorous error bounds on the real math
> >library functions.
> 
> I think INF/NaN behaviour at the fundamental level is flawed.
> 
> This initialization:
> 
> 	double complex x = 1.0e+200 + INFINITY * I;
> 
> on every compiler I try, yields an 'x' of
> 
> 	NaN + INFINITY i

This is expected unless the implementation supports pure-imaginary
types and a _Imaginary_I (as opposed to _Complex_I). Note that Annex G
requires this, but GCC treats it as optional and does not support it
despite claiming Annex G conformance.

In this particular kind of case, the right solution is to use the
CMLPX macro instead of the * operator with I:

	double complex x = CMPLX(1.0e+200, INFINITY);

> Whereas if I compute
> 
> 	double complex a = 2.0 + 1.0e200 * I;
> 	double complex b = 1.0e200 + 1.0 * I;
> 	double x = a * b;
> 
> then 'x' prints correctly as
> 
> 	1.0e+200 + INF * I;

Indeed the compiler is required to handle these overflow cases unless
#pragma STDC CX_LIMITED_RANGE ON is in effect. I don't know if GCC
honors the pragma but it has -fcx-limited-range to set it globally.
Note that without CX_LIMITED_RANGE, complex math performance is
atrociously bad due to extensive overflow checking.

Rich

      reply	other threads:[~2020-02-12  4:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 15:51 mg1633068
2020-02-11 19:30 ` Szabolcs Nagy
2020-02-11 23:24   ` Rich Felker
2020-02-12  0:46     ` Damian McGuckin
2020-02-12  2:00       ` Rich Felker
2020-02-12  4:07         ` Damian McGuckin
2020-02-12  4:19           ` Rich Felker [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=20200212041912.GW1663@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --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).