Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Nov 2019 21:40:40 +0100
From:      Dimitry Andric <dim@FreeBSD.org>
To:        freebsd-numerics@freebsd.org
Subject:   Re: UB in various hypot() implementations (left-shifting a negative,  number)
Message-ID:  <a3fe6fb4-8f33-6d10-64d4-e722bfebcc85@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
On 2019-11-16 18:02:29 UTC, Steve Kargl wrote:
 > The patch for hypotl() is likely unneeded as there is no shifting
 > of a negative integer in the code being changed.  Does csqrt_test.c
 > pass without Jeff's patch?

Yes, it passes.


 > This is the original code
 >
 >      u_int32_t high;
 >      t1 = 1.0;
 >      GET_HIGH_WORD(high,t1);
 >      SET_HIGH_WORD(t1,high+DESW(k));
 >
 > high + DESW(k) = high + k
 >                = 16383 + k
 >
 > and this is the code after the patch
 >
 >      t1 = 0.0;
 >      SET_HIGH_WORD(t1,ESW(k));
 >
 > ESW(k) = MAX_EXP - 1 + k
 >        = LDBL_MAX_EXP - 1 + k
 >        = 16384 - 1 + k
 >        = 16383 + k
 >
 > So, in principle there is no functional change.

What about t1 changing from 1.0 to 0?  If I revert just that line, all
tests do pass, including the csqrt test.

-Dimitry

PS: Apologies for any missing References: header in this mail, which 
might mess up threading in your mail client. I just subscribed to this list.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a3fe6fb4-8f33-6d10-64d4-e722bfebcc85>