This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 0/2] New strfrom functions
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Florian Weimer <fw at deneb dot enyo dot de>
- Cc: "Gabriel F. T. Gomes" <gftg at linux dot vnet dot ibm dot com>, <libc-alpha at sourceware dot org>
- Date: Fri, 26 Aug 2016 00:03:28 +0000
- Subject: Re: [PATCH 0/2] New strfrom functions
- Authentication-results: sourceware.org; auth=none
- References: <1471967068-28888-1-git-send-email-gftg@linux.vnet.ibm.com> <87vaypt6rz.fsf@mid.deneb.enyo.de>
On Thu, 25 Aug 2016, Florian Weimer wrote:
> Does the standard also contain some gdtoa-like functionality (string
> formatting which results in the shortest possible representation and
> converts back to the original number)?
Such an operation is not an IEEE 754-2008 operation, and the purpose of TS
18661 is to provide bindings to IEEE 754-2008 (although it sometimes goes
beyond what IEEE 754 has - for example, 18661-4 includes a tanpi function
where IEEE 754 only has sinpi and cospi).
> This seems to be lacking from the standard library, and it is rather
> non-trivial to implement efficiently.
It seems rather underspecified (is it the shortest input to strtod that
returns the original result in round-to-nearest? in the rounding mode used
when calling the function producing the string? restricted to decimal
strings rather than hex? restricted to decimal strings with a particular
format, such as with or without an exponent? required to be the closest
string with that number of digits in the decimal mantissa even when you
could get a shorter result by allowing a string that is not closest for
its number of digits? what should be done for infinities and NaNs? what
are requirements regarding raising "inexact"?).
But whatever specification you take for such an operation (and it's not
clear there is a consensus one suitable for all users, given all the
choices to be made), clearly you can (for IEEE formats) bound the internal
precision needed to not much more than twice the precision of the input;
you never need to calculate anything with precision on the order of the
maximum exponent as you can for worst cases of printf and strtod. (And
you can trade off between speed and space used for precomputed data.)
--
Joseph S. Myers
joseph@codesourcery.com