This is the mail archive of the libc-help@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: strtod thousands separator


Hi Florian,
thank you for your reply. I would like to help to improve the
documentation if that's possible. Do you think the following ideas are
worth sending as a proper patch ?

- In the section "Input-Conversion-Syntax", the scanf flags '*' and
'a' are described. Maybe add the "'" flag here ? (reading the source,
also document the "I" flag here ? see
https://sourceware.org/bugzilla/show_bug.cgi?id=10892)

- In the section "Parsing-of-Integers" (the one documenting strtol),
the following note refers to scanf and the "'" flag:
"All the functions mentioned in this section so far do not handle
alternative representations of characters as described in the locale
data. Some locales specify thousands separator and the way they have
to be used which can help to make large numbers more readable. To read
such numbers one has to use the scanf functions with the â'â flag."
Maybe a similar note should be present in Parsing-of-Floats (the one
documenting strtod) ? Something like
"All the functions handle alternative representations for the decimal
point, but do not handle other locale dependent representations such
as the thousands separator or localized digits. To read such numbers
one has to use the scanf functions with the â'â or 'I' flag." (Also
maybe add the part about localized digit to the "Parsing-of-Integers"
note about scanf ?)

- In the section Parsing-of-Floats (the one documenting strtod), the
following sentence is not very helpful:
"In a locale other than the standard "C" or "POSIX" locales, this
function may recognize additional locale-dependent syntax." It comes
directly from the C standard. But I don't think it should be in the
documentation of an implementation of the standard. Reading the
source, the decimal separator seems to be the localized feature of
strtod and it's already documented just above. So maybe remove the
sentence entirely ?

Regards,
Jon

Jon


On Sat, Oct 3, 2015 at 10:07 PM, Florian Weimer <fweimer@redhat.com> wrote:
> On 10/02/2015 12:41 PM, Jon Harper wrote:
>> Hi,
>> I noticed that the function __strtod_internal has a 'group' parameter
>> to accept correctly grouped strings with thousands separators from the
>> user's locale. But strtod calls __strtod_internal with group=0, so it
>> always disables this feature.
>>
>> What is the rationale here ?
>>
>> If thousands separator handling is needed, is the correct way to use
>> the feature to copy/paste the declaration of __strtod_internal because
>> it's not in headers and call it directly with group=1 ?
>
> You should use the scanf family of functions and the ' flag.  Quoting
> from the manual:
>
> â
> For all the above number parsing formats there is an additional
> optional flag '''.  When this flag is given the 'scanf' function expects
> the number represented in the input string to be formatted according to
> the grouping rules of the currently selected locale [â].
> â
>
> Admittedly, this information is difficult to find unless you already
> know what you are looking for.
>
> Florian


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