Re: [PATCHv2 5/6] Use floating point for --dirstat percentages
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: 2016-06-15 22:51:06
On Tue, Apr 26, 2011 at 7:12 PM, Johan Herland [off-list ref] wrote:
Allow specifying --dirstat cut-off percentage as a floating point number. When printing the dirstat output, floating point numbers are presented in rounded form (as opposed to truncated). Therefore, this patch includes a significant churn in the expected output of the dirstat selftests.
Hmm. So thinking more about this, I do think it's preferable that the percentages never be rounded up. Why? Having them add up to 99.9 due to rounding error makes a ton more sense to me than having percentages add up to 100.1 But I guess I don't care _that_ much, since most of the time I use "cumulative", where you don't much have that issue anyway. Also:
Remaining questions: - Locale issues with strod(), e.g. decimal separator is a comma in certain locales.
I think this is a serious issue. Of course, any sane user will have
the numeric locale be set to "C", but we know that any argument that
depends on sane users is likely broken.
So regardless of the rounding, I do think we should make sure that we have a
setlocale(LC_NUMERIC, "C");
both for the parsing _and_ for the printout. And if somebody really
wants the locale to affect these kinds of things, we might have a
config option to allow it, but I think we should default to a nice
fixed format in this case.
(I don't know anybody who uses LC_NUMERIC that actually sets the
decimal point character to ',' though - it is bound to break a ton of
applications. And I say that as somebody who grew up with a "decimal
comma").
Linus