From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 63F85385481F for ; Wed, 23 Jun 2021 16:19:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 63F85385481F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: d/K8i8PtcPR4SyA57YpwreHzIYw7zVy22Hzgoq/lvwi0HKTzb5wlE9wqcRACvyACLZtlEGyZcs wtYcg+HIsPHZLNXVY5MYtDupsUDLlv3oKVBojsmJjzBO0zP/s1JB7ckhV9ESdOZE/scSG51URg Wv65X085OHmLLcRxyNP8RxXpfVDg6O12tVvbKWPT3WBd+beTtc18VznwwfigoQYVAiDLj6TJd/ kjYsOmrN4Hidd5aaRu/pBgVgUyDJy7PxXmGATOFNMYIKa3Gec+5Lh1/oq92cVfzVBfc5eTNtGh uv0= X-IronPort-AV: E=Sophos;i="5.83,294,1616486400"; d="scan'208";a="62737001" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 23 Jun 2021 08:19:51 -0800 IronPort-SDR: NAkOLD4Is+tWyihRZFfU6jCueKlqcR2259HCJAX1SWJRcNgb3GFETtQ0YcphwA7x7p5XXZDRyE +lfg6AjWSncmbObS6FqXLwkZEQRiir+ZW4AZtXXecsb17HjzF605NspowTHTa4qOGLVSR7igWh j61v63PpBsnWJiup7gLzo5jpDeyESwqm7jTmSCi6uynYJGlHRhblDor5nJwfCV14j4PzkAXXv4 cAPmwZe7WRiZG1f+puwozwfYwdPUc+JUTw5kaQ9yn1X5Y2vlzz8Aa/RVhRfoE7RpHhjHsn+ev/ fbU= Date: Wed, 23 Jun 2021 16:19:45 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Keith Packard CC: Subject: Re: [PATCH] stdlib: Make strtod/strtof set ERANGE consistently for underflow. In-Reply-To: <874kdppp5w.fsf@keithp.com> Message-ID: References: <878s31pz7i.fsf@keithp.com> <874kdppp5w.fsf@keithp.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-07.mgc.mentorg.com (139.181.222.7) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3120.5 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jun 2021 16:19:55 -0000 On Tue, 22 Jun 2021, Keith Packard wrote: > Thanks for this clarification; I didn't realize that underflow had this > additional subtly. It sounds like this means that there are additional > cases where errno should be set to ERANGE in the code. I'm afraid I > don't understand the workings of this function well enough to know how > to detect this particular case. Could we somehow detect this using > exceptions? Or are there places in the code which could add some direct > checks? Detecting with exceptions is tricky, since (a) you'd need to save and clear any underflow exceptions raised before strtod is called, then merge them with the exceptions raised in strtod before returning and (b) the strtod code would also need to ensure that the correct exceptions are raised in all cases, which itself is tricky (and once you have logic to ensure the correct exceptions are raised in all cases, it's probably simpler to use that logic to drive setting errno as well, rather than deducing the errno setting from what exceptions were raised). I'm not familiar enough with the newlib strtod code to know where you might need to add direct checks (including dealing with architecture-specific configuration of whether tininess is detected before and after rounding). (The sort of case where before-rounding versus after-rounding tininess detection matters and a result rounding to the least normal value is still considered to underflow is: for round-to-nearest, if the mathematical result is between 1/2 (inclusive) and 3/4 (exclusive) of the way from the greatest subnormal value to the least normal value, then it rounds to the least normal value but still is considered to underflow for both before-rounding and after-rounding tininess detection; if it's at least 3/4 of the way from the greatest subnormal value to the least normal value, it only underflows for before-rounding tininess detection but not for after-rounding tininess detection.) -- Joseph S. Myers joseph@codesourcery.com