diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2020-10-08 13:09:49 +0200 |
---|---|---|
committer | laforge <laforge@osmocom.org> | 2020-10-09 19:23:34 +0000 |
commit | 6d744989e2df3e044e8ef53fe50591363ca7c942 (patch) | |
tree | 2b2bfef8917ec57f3c4671619ccbe1df2b22fc51 /src | |
parent | a07f25e3bac0f44e84433c35dca5e491a2df59d2 (diff) |
doc tweaks for osmo_float_str_to_int(), osmo_int_to_float_str*()
Drop nonexistent arg from api doc, fix "factor of a million", and explain a bit
more.
Change-Id: I131e839b6b7dd601b859313b358d346904c0e145
Diffstat (limited to 'src')
-rw-r--r-- | src/utils.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/utils.c b/src/utils.c index 7fd7223a..f5896c41 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1214,9 +1214,11 @@ bool osmo_str_startswith(const char *str, const char *startswith_str) * 10 to-the-power-of precision to obtain the returned integer. * The usable range of digits is -INT64_MAX .. INT64_MAX -- note, not INT64_MIN! The value of INT64_MIN is excluded to * reduce implementation complexity. See also utils_test.c. + * The advantage over using sscanf("%f") is guaranteed precision: float or double types may apply rounding in the + * conversion result. osmo_float_str_to_int() and osmo_int_to_float_str_buf() guarantee true results when converting + * back and forth between string and int. * \param[out] val Returned integer value. * \param[in] str String of a float, like '-12.345'. - * \param[in] in_len Length of string to parse, or -1 to use strlen(str). * \param[in] precision Fixed-point precision, or * \returns 0 on success, negative on error. */ int osmo_float_str_to_int(int64_t *val, const char *str, unsigned int precision) @@ -1331,8 +1333,14 @@ int osmo_float_str_to_int(int64_t *val, const char *str, unsigned int precision) return 0; } -/*! Convert an integer with a factor of a million to a floating point string. +/*! Convert an integer to a floating point string using a decimal quotient (fixed-point precision). * For example, with precision = 3, convert -1230 to "-1.23". + * The usable range of digits is -INT64_MAX .. INT64_MAX -- note, not INT64_MIN! The value of INT64_MIN is excluded to + * reduce implementation complexity. See also utils_test.c. + * The advantage over using printf("%.6g") is guaranteed precision: float or double types may apply rounding in the + * conversion result. osmo_float_str_to_int() and osmo_int_to_float_str_buf() guarantee true results when converting + * back and forth between string and int. + * The resulting string omits trailing zeros in the fractional part (like "%g" would) but never applies rounding. * \param[out] buf Buffer to write string to. * \param[in] buflen sizeof(buf). * \param[in] val Value to convert to float. |