HEADSUP: math is broken with clang and optimization

Steve Kargl sgk at troutmask.apl.washington.edu
Sun Feb 14 22:00:10 UTC 2021


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

% cc -o testf -O2 -pipe -static -Wall -fno-builtin \
  -I/usr/home/kargl/include -I/usr/local/include -I../mp \
  -I../libm/msun/src testf.c  -L/usr/home/kargl/lib \
  -L/usr/local/lib -L../mp -L../libm/msun -lmpsk -lmpfr -lgmp -lm
% ./testf -u -n 1 -X 10
Max ULP Re: 136633.320045
Max ULP Im: 1890038.672637

% cc -o testf -O0 -pipe -static -Wall -fno-builtin \
  -I/usr/home/kargl/include -I/usr/local/include -I../mp \
  -I../libm/msun/src testf.c  -L/usr/home/kargl/lib \
  -L/usr/local/lib -L../mp -L../libm/msun -lmpsk -lmpfr -lgmp -lm
% ./testf -u -n 1 -X 10
Max ULP Re: 2.785010
Max ULP Im: 2.926068

One of these is more correct than the other.

-- 
Steve


More information about the freebsd-current mailing list