diff options
author | Pádraig Brady <P@draigBrady.com> | 2015-06-22 04:19:48 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2015-06-22 17:22:04 +0100 |
commit | 4f824b3f3658a941187a32c6d52ee758e4db5896 (patch) | |
tree | f2e2a0c1d852a5d74fe276a225d3a5e87717f2bd /src | |
parent | bc9d16b79f4e8c25e13be63f846cfd7152b65da1 (diff) | |
download | coreutils-4f824b3f3658a941187a32c6d52ee758e4db5896.tar.xz |
numfmt: don't hardcode floating point limits
* src/numfmt.c (MAX_UNSCALED_DIGITS): Set this to LDBL_DIG
rather than hardcoding at 18 for better portability.
* tests/misc/numfmt.pl: Restrict limit tests to supported platforms.
Diffstat (limited to 'src')
-rw-r--r-- | src/numfmt.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/numfmt.c b/src/numfmt.c index 1a7185f2b..4af16faea 100644 --- a/src/numfmt.c +++ b/src/numfmt.c @@ -153,7 +153,7 @@ enum { DELIMITER_DEFAULT = CHAR_MAX + 1 }; /* Maximum number of digits we can safely handle without precision loss, if scaling is 'none'. */ -enum { MAX_UNSCALED_DIGITS = 18 }; +enum { MAX_UNSCALED_DIGITS = LDBL_DIG }; /* Maximum number of digits we can work with. This is equivalent to 999Y. @@ -589,7 +589,7 @@ simple_strtod_float (const char *input_str, Returns: SSE_OK - valid number. - SSE_OK_PRECISION_LOSS - if more than 18 digits were used. + SSE_OK_PRECISION_LOSS - if more than LDBL_DIG digits were used. SSE_OVERFLOW - if more than 27 digits (999Y) were used. SSE_INVALID_NUMBER - if no digits were found. SSE_VALID_BUT_FORBIDDEN_SUFFIX @@ -604,9 +604,12 @@ simple_strtod_human (const char *input_str, /* 'scale_auto' is checked below. */ int scale_base = default_scale_base (allowed_scaling); - devmsg ("simple_strtod_human:\n input string: %s\n " - "locale decimal-point: %s\n", - quote_n (0, input_str), quote_n (1, decimal_point)); + devmsg ("simple_strtod_human:\n input string: %s\n" + " locale decimal-point: %s\n" + " MAX_UNSCALED_DIGITS: %d\n", + quote_n (0, input_str), + quote_n (1, decimal_point), + MAX_UNSCALED_DIGITS); enum simple_strtod_error e = simple_strtod_float (input_str, endptr, value, precision); |