public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Joseph Myers <joseph@codesourcery.com>
To: Keith Packard <keithp@keithp.com>
Cc: <newlib@sourceware.org>
Subject: Re: [PATCH] stdlib: Make strtod/strtof set ERANGE consistently for underflow.
Date: Wed, 23 Jun 2021 16:19:45 +0000	[thread overview]
Message-ID: <alpine.DEB.2.22.394.2106231609510.13671@digraph.polyomino.org.uk> (raw)
In-Reply-To: <874kdppp5w.fsf@keithp.com>

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

  reply	other threads:[~2021-06-23 16:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 17:48 Keith Packard
2021-06-22 20:31 ` Joseph Myers
2021-06-22 21:25   ` Keith Packard
2021-06-23 16:19     ` Joseph Myers [this message]
2021-06-28 20:38     ` Jeff Johnston
2021-06-28 20:44       ` Joseph Myers
2021-07-07 17:22 ` Jeff Johnston

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.22.394.2106231609510.13671@digraph.polyomino.org.uk \
    --to=joseph@codesourcery.com \
    --cc=keithp@keithp.com \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).