mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: catan errors
Date: Wed, 11 Apr 2018 02:52:11 +0200	[thread overview]
Message-ID: <20180411005211.GL4418@port70.net> (raw)
In-Reply-To: <20180410232328.GN3094@brightrain.aerifal.cx>

* Rich Felker <dalias@libc.org> [2018-04-10 19:23:28 -0400]:
> On Wed, Apr 11, 2018 at 01:08:50AM +0200, Szabolcs Nagy wrote:
> > * Rich Felker <dalias@libc.org> [2018-04-10 15:50:07 -0400]:
> > >  	t = y - 1.0;
> > >  	a = x2 + (t * t);
> > > -	if (a == 0.0)
> > > -		goto ovrf;
> > 
> > why does a==0 imply x==0?
> 
> OK, at least by my reasoning it's only algebraically true not
> necessarily as doubles.
> 
> > if |x| < sqrt(2)*0x1p-538, x2 underflows to 0 in nearest rounding mode.
> > 
> > to handle this correctly extra work would need to be done, so i think
> > either way is fine (leaving the goto there or not are both wrong, but
> > we dont guarantee correct complex functions yet)
> 
> I'm fine with just moving the check back here. But the special case
> (maybe not near-special cases with internal over/underflow though)
> works fine just replacing the *I with CMPLX. See attached.
> 

i think this makes sense for now.

> Rich

> diff --git a/src/complex/catan.c b/src/complex/catan.c
> index 39ce6cf..7dc2afe 100644
> --- a/src/complex/catan.c
> +++ b/src/complex/catan.c
> @@ -91,29 +91,17 @@ double complex catan(double complex z)
>  	x = creal(z);
>  	y = cimag(z);
>  
> -	if (x == 0.0 && y > 1.0)
> -		goto ovrf;
> -
>  	x2 = x * x;
>  	a = 1.0 - x2 - (y * y);
> -	if (a == 0.0)
> -		goto ovrf;
>  
>  	t = 0.5 * atan2(2.0 * x, a);
>  	w = _redupi(t);
>  
>  	t = y - 1.0;
>  	a = x2 + (t * t);
> -	if (a == 0.0)
> -		goto ovrf;
>  
>  	t = y + 1.0;
>  	a = (x2 + t * t)/a;
> -	w = w + (0.25 * log(a)) * I;
> -	return w;
> -
> -ovrf:
> -	// FIXME
> -	w = MAXNUM + MAXNUM * I;
> +	w = CMPLX(w, 0.25 * log(a));
>  	return w;
>  }



      reply	other threads:[~2018-04-11  0:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-10 19:50 Rich Felker
2018-04-10 20:23 ` dgutson .
2018-04-10 20:32   ` Rich Felker
2018-04-10 20:41     ` dgutson .
2018-04-10 20:50       ` Rich Felker
2018-04-10 21:27         ` dgutson .
2018-04-10 22:14           ` Rich Felker
2018-04-10 23:08 ` Szabolcs Nagy
2018-04-10 23:23   ` Rich Felker
2018-04-11  0:52     ` Szabolcs Nagy [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=20180411005211.GL4418@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).