Change in libosmocore[master]: doc tweaks for osmo_float_str_to_int(), osmo_int_to_float_str*()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

neels gerrit-no-reply at lists.osmocom.org
Thu Oct 8 11:17:31 UTC 2020


neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/20480 )


Change subject: doc tweaks for osmo_float_str_to_int(), osmo_int_to_float_str*()
......................................................................

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
---
M src/utils.c
1 file changed, 10 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/80/20480/1

diff --git a/src/utils.c b/src/utils.c
index c0ab166..fffc901 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1214,9 +1214,11 @@
  * 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 @@
 	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.

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/20480
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I131e839b6b7dd601b859313b358d346904c0e145
Gerrit-Change-Number: 20480
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201008/5a9c2383/attachment.htm>


More information about the gerrit-log mailing list