This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 0/2] New strfrom functions


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]