MCPcopy Create free account
hub / github.com/coreutils/coreutils / parse_human_number

Function parse_human_number

src/numfmt.c:1211–1233  ·  view source on GitHub ↗

Parse a numeric value (with optional suffix) from a string. Returns a long double value, with input precision. If there's an error converting the string to value - exits with an error. If there are any trailing characters after the number (besides a valid suffix) - exits with an error. */

Source from the content-addressed store, hash-verified

1209 If there are any trailing characters after the number
1210 (besides a valid suffix) - exits with an error. */
1211static enum simple_strtod_error
1212parse_human_number (char const *str, long double /*output */ *value,
1213 size_t *precision)
1214{
1215 char *ptr = NULL;
1216
1217 enum simple_strtod_error e =
1218 simple_strtod_human (str, &ptr, value, precision, scale_from);
1219 if (e != SSE_OK && e != SSE_OK_PRECISION_LOSS)
1220 {
1221 simple_strtod_fatal (e, str);
1222 return e;
1223 }
1224
1225 if (ptr && *ptr != '\0')
1226 {
1227 if (inval_style != inval_ignore)
1228 error (conv_exit_code, 0, _("invalid suffix in input %s: %s"),
1229 quote_n (0, str), quote_n (1, ptr));
1230 e = SSE_INVALID_SUFFIX;
1231 }
1232 return e;
1233}
1234
1235
1236/* Print the given VAL, using the requested representation.

Callers 1

process_suffixed_numberFunction · 0.85

Calls 2

simple_strtod_humanFunction · 0.85
simple_strtod_fatalFunction · 0.85

Tested by

no test coverage detected