]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/commit
r355120 | dim | 2019-11-26 23:01:09 +0100 (Tue, 26 Nov 2019) | 32 lines
authordim <dim@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 4 Dec 2019 17:45:34 +0000 (17:45 +0000)
committerdim <dim@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 4 Dec 2019 17:45:34 +0000 (17:45 +0000)
commit3884948b7190448ba92eae205532a30637d0d810
treeaaef96f288d458b09c497c09e0c7ee17aa7b5409
parentc95ee20e10dae9ef627d80bd0d52c7ed12ccb060
r355120 | dim | 2019-11-26 23:01:09 +0100 (Tue, 26 Nov 2019) | 32 lines

The fdlibm hypot() implementations shouldn't potentially left-shift
negative numbers (invoking undefined behavior)

Summary:
Various paths through hypot(x, y) will multiply x and y by a power of
two, perform the calculation in a range where IEEE-754 provides greater
precision, then undo the multiplication to determine the true result.
Undoing that multiplication is implemented as t1*w, where t1=2**k.

2**k is often computed by taking the high word of 1.0, then adding k<<20
(for doubles or long doubles) or k<<23 (for floats) to it, then
overwriting that high word. But when k is negative this left-shifts a
negative value -- and that's undefined behavior in many editions of C
and C++.

This patch should fix all hypot implementations to compute 2**k without
triggering this particular bit of undefined behavior.

Test Plan: I've only very lightly tested out the hypot(double, double)
change, in SpiderMonkey's JavaScript engine, for consistency with prior
behavior.  The other functions' changes have more or less only been
eyeballed.  Careful examination appreciated!  Do note, however, that an
error in any of these changes would most likely produce a value that is
incorrect by a factor of two, so any mistake would most likely be
glaring if invoked.

Submitted by: Jeff Walden <jwalden@mit.edu>
Obtained from: https://github.com/freebsd/freebsd/pull/414
Reviewed by: dim, lwhsu
Differential Revision: https://reviews.freebsd.org/D22354

git-svn-id: svn://svn.freebsd.org/base/stable/10@355395 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
lib/msun/src/e_hypot.c
lib/msun/src/e_hypotf.c