freebsd-dev/lib/msun
Dimitry Andric 5763a8cf06 Do not left-shift a negative number (inducing undefined behavior in
C/C++) in exp(3), expf(3), expm1(3) and expm1f(3) during intermediate
computations that compute the IEEE-754 bit pattern for |2**k| for
integer |k|.

The implementations of exp(3), expf(3), expm1(3) and expm1f(3) need to
compute IEEE-754 bit patterns for 2**k in certain places.  (k is an
integer and 2**k is exactly representable in IEEE-754.)

Currently they do things like 0x3FF0'0000+(k<<20), which is to say they
take the bit pattern representing 1 and then add directly to the
exponent field to get the desired power of two.  This is fine when k is
non-negative.

But when k<0 (and certain classes of input trigger this), this
left-shifts a negative number -- an operation with undefined behavior in
C and C++.

The desired semantics can be achieved by instead adding the
possibly-negative k to the IEEE-754 exponent bias to get the desired
exponent field, _then_ shifting that into its proper overall position.

(Note that in case of s_expm1.c and s_expm1f.c, there are SET_HIGH_WORD
and SET_FLOAT_WORD uses further down in each of these files that perform
shift operations involving k, but by these points k's range has been
restricted to 2 < k <= 56, and the shift operations under those
circumstances can't do anything that would be UB.)

Submitted by:	Jeff Walden, https://github.com/jswalden
Obtained from:	https://github.com/freebsd/freebsd/pull/411
Obtained from:	https://github.com/freebsd/freebsd/pull/412
MFC after:	3 days
2019-09-25 18:50:57 +00:00
..
aarch64
amd64 Resolve conflicts between macros in fenv.h and ieeefp.h 2018-05-31 20:22:47 +00:00
arm lib: further adoption of SPDX licensing ID tags. 2017-11-26 02:00:33 +00:00
bsdsrc Remove an unused incude from lib/msun/bsdsrc/b_log.c. 2017-12-07 20:41:23 +00:00
i387 Resolve conflicts between macros in fenv.h and ieeefp.h 2018-05-31 20:22:47 +00:00
ld80 Recommit r336497: Fix powl, cpow, cpowf, and cpowl imports from OpenBSD 2018-07-20 18:27:30 +00:00
ld128 msun: Fix some old typos. 2018-12-31 15:43:06 +00:00
man Introduce <sys/qmath.h>, a fixed-point math library from Netflix. 2019-08-27 11:46:22 +00:00
mips lib: further adoption of SPDX licensing ID tags. 2017-11-26 02:00:33 +00:00
powerpc lib: further adoption of SPDX licensing ID tags. 2017-11-26 02:00:33 +00:00
riscv Replace SOFTFLOAT with __riscv_float_abi_*. 2018-04-19 20:36:15 +00:00
sparc64 lib: further adoption of SPDX licensing ID tags. 2017-11-26 02:00:33 +00:00
src Do not left-shift a negative number (inducing undefined behavior in 2019-09-25 18:50:57 +00:00
tests Unskip test cases from netbsd-tests by defining __HAVE_FENV 2019-08-31 20:45:45 +00:00
x86 Resolve conflicts between macros in fenv.h and ieeefp.h 2018-05-31 20:22:47 +00:00
Makefile libm: squelch -Woverflow from gcc6 2019-02-01 23:15:54 +00:00
Makefile.depend DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
Symbol.map msun: add ld80/ld128 powl, cpow, cpowf, cpowl from openbsd 2018-07-15 00:23:10 +00:00