Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Mar 2016 11:25:21 -0700
From:      Steve Kargl <sgk@troutmask.apl.washington.edu>
To:        freebsd-toolchain@freebsd.org
Subject:   clang gets numerical underflow wrong, please fix.
Message-ID:  <20160313182521.GA25361@troutmask.apl.washington.edu>

next in thread | raw e-mail | index | archive | help
Consider this small piece of code:

#include <fenv.h>
#include <stdio.h>

float
foo()
{
	static const volatile float tiny = 1.e-30f;
	return (tiny * tiny);
}

int
main(void)
{
   float x;
   feclearexcept(FE_ALL_EXCEPT);
   x = foo();
   if (fetestexcept(FE_UNDERFLOW)) printf("FE_UNDERFLOW: ");
   printf("x = %e\n", x);
   return 0;
}

clang seems to get the underflow condition wrong.

% cc -o z a.c -lm && ./z
FE_UNDERFLOW: x = 0.000000e+00

% cc -O -o z a.c -lm && ./z
x = 1.000000e-60             <--- This is not a possible value!

% gcc -o z a.c -lm && ./z
FE_UNDERFLOW: x = 0.000000e+00

% gcc -O -o z a.c -lm && ./z
FE_UNDERFLOW: x = 0.000000e+00

% uname -a
FreeBSD laptop-kargl 11.0-CURRENT FreeBSD 11.0-CURRENT #1 r296724:
Sun Mar 13 09:12:38 PDT 2016

% cc --version
FreeBSD clang version 3.8.0 (tags/RELEASE_380/final 262564)
(based on LLVM 3.8.0)

% gcc --version
gcc (FreeBSD Ports Collection) 4.8.5

-- 
Steve



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