From owner-freebsd-numerics@freebsd.org Sat Nov 16 20:40:57 2019 Return-Path: Delivered-To: freebsd-numerics@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 89B6A1ADB93 for ; Sat, 16 Nov 2019 20:40:57 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47FnDT1hFhz3Cxs for ; Sat, 16 Nov 2019 20:40:57 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [IPv6:2001:470:7a58:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "tensor.andric.com", Issuer "Let's Encrypt Authority X3" (verified OK)) (Authenticated sender: dim) by smtp.freebsd.org (Postfix) with ESMTPSA id BC64E16021 for ; Sat, 16 Nov 2019 20:40:56 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from [IPv6:2001:470:7a58:0:2452:2375:71a2:2897] (unknown [IPv6:2001:470:7a58:0:2452:2375:71a2:2897]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 4E4132C5C4 for ; Sat, 16 Nov 2019 21:40:41 +0100 (CET) To: freebsd-numerics@freebsd.org From: Dimitry Andric Subject: Re: UB in various hypot() implementations (left-shifting a negative, number) Message-ID: Date: Sat, 16 Nov 2019 21:40:40 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Nov 2019 20:40:57 -0000 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.