Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Feb 2021 12:49:13 -0800
From:      Steve Kargl <sgk@troutmask.apl.washington.edu>
To:        freebsd-current@freebsd.org
Subject:   Re: HEADSUP: math is broken with clang and optimization
Message-ID:  <20210215204913.GA86364@troutmask.apl.washington.edu>
In-Reply-To: <20210214215958.GA80810@troutmask.apl.washington.edu>
References:  <20210214215958.GA80810@troutmask.apl.washington.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Feb 14, 2021 at 01:59:58PM -0800, Steve Kargl wrote:
> Just a headsup for anyone doing numerical work with
> FreeBSD-current.  clang with optimization of -O1 or
> higher produces wrong results.  Testing 1 million 
> complex values of ccoshf and limiting |z| < 20,
> shows
> 

This is either an in-ling bug or discarding a cast issue.
With everything in the same file so clang has dp_ccosh
available to it when compiling main.

void
dp_ccosh(double x, double y, double *re, double *im)
{
	*re = cosh(x) * cos(y);
	*im = sinh(x) * sin(y);
}

int
main(int argc, char *argv[])
{
   float complex f, z;
   double re, im, ur, ui;
   float x, y;
   float xmax;
...
   for (j = 0; j < NUM; j++) {

       x = xmax * rangef();
       y = xmax * rangef();
       z = CMPLXF(x,y);
       f = ccoshf(z);

       dp_ccosh((double)x, (double)y, &re, &im);


gives the wrong results.  Changing this to

int
main(int argc, char *argv[])
{
   float complex f, z;
   double re, im, ur, ui;
   float x, y;
   volatile float xv, yv;
   float xmax;
...
   for (j = 0; j < NUM; j++) {

       xv = x = xmax * rangef();
       yv = y = xmax * rangef();
       z = CMPLXF(x,y);
       f = ccoshf(z);

       dp_ccosh((double)xv, (double)yv, &re, &im);

gives the expected and correct results.

-- 
Steve



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20210215204913.GA86364>