public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joseph Myers <joseph@codesourcery.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Florian Weimer <fweimer@redhat.com>, <libstdc++@gcc.gnu.org>,
	<gcc-patches@gcc.gnu.org>
Subject: Re: [committed] libstdc++: Add std::from_chars for floating-point types
Date: Tue, 21 Jul 2020 20:08:53 +0000	[thread overview]
Message-ID: <alpine.DEB.2.21.2007211956020.21027@digraph.polyomino.org.uk> (raw)
In-Reply-To: <20200721110418.GH3215@redhat.com>

On Tue, 21 Jul 2020, Jonathan Wakely via Gcc-patches wrote:

> I also noticed some strings give an underflow error with glibc's
> strtod, but are valid for the Microsoft implementation. For example,
> this one:
> https://github.com/microsoft/STL/blob/master/tests/std/tests/P0067R5_charconv/double_from_chars_test_cases.hpp#L265
> 
> Without the final '1' digit glibc returns DBL_MIN, but with the final
> '1' digit (so a number larger than DBL_MIN) it underflows. Is that
> expected?

That's DBL_TRUE_MIN, not DBL_MIN.  The IEEE rule is that, with default 
exception handling, an exact subnormal result does not raise the underflow 
exception flag, whereas an inexact tiny result raises both inexact and 
underflow flags; glibc mostly doesn't try to ensure an (exact) underflow 
exception is signaled for the case of exact underflow with traps on that 
exception enabled, only correct flags raised with default exception 
handling.

(The way tininess is determined depends on the architecture.  glibc strtod 
handles both cases, before-rounding and after-rounding architectures, 
modulo oddities where implementations of some CPU architectures don't 
appear to be consistent in their before-rounding / after-rounding choice.  
Note that on after-rounding architectures it depends on the result after 
rounding with normal precision but unbounded exponent range.  One 
consequence of that is that the bound on the number of digits after the 
decimal point that may need to be considered, beyond just knowing whether 
any of them are nonzero, to determine the correctly rounded result and 
exceptions, is e.g. 1076 for binary64, not 1075; that is, two digits are 
needed beyond those needed for an exact representation of the least 
subnormal value, although only one such digit is needed for the correctly 
rounded result if you ignore after-rounding tininess detection.)

-- 
Joseph S. Myers
joseph@codesourcery.com

  reply	other threads:[~2020-07-21 20:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-20 22:52 Jonathan Wakely
2020-07-21  5:56 ` Florian Weimer
2020-07-21 11:04   ` Jonathan Wakely
2020-07-21 20:08     ` Joseph Myers [this message]
2020-07-22 15:09       ` Jonathan Wakely
2020-08-03 11:47     ` Florian Weimer
2020-08-03 12:30       ` Jonathan Wakely
2020-07-27  9:41 ` Rainer Orth
2020-07-27  9:46   ` Jonathan Wakely
2020-07-28 21:01     ` Jonathan Wakely
2020-07-28 21:02       ` Jonathan Wakely

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.21.2007211956020.21027@digraph.polyomino.org.uk \
    --to=joseph@codesourcery.com \
    --cc=fweimer@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jwakely@redhat.com \
    --cc=libstdc++@gcc.gnu.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).