vppinfra: fix float rounding in format function 95/42095/1
authorPierre Pfister <[email protected]>
Thu, 19 Dec 2024 15:49:21 +0000 (16:49 +0100)
committerPierre Pfister <[email protected]>
Tue, 7 Jan 2025 08:47:55 +0000 (09:47 +0100)
commitc75671fbb0d8285a4232d4a2bb0cc5bf713b85b6
tree0aba3dcebf8dc91dd1ff60e3bfc14d08aad21508
parent7cb30d37226014281d4df2a048bac57c7cb25e70
vppinfra: fix float rounding in format function

The current VPP formating for floats tries to round number to the
closest value (depending on the number of requested digits), but fails
to do so when the last printed digit is 9 (because carries are hard...).

This commits fixes this by adding 0.5 * 10^n_fraction_digits
to the value and then ignoring digits past the printed ones.

Note that when the number is exactly midway, like 9.5, the value is
rounded up, as this seems to be the clib behavior as well.

Type: fix
Change-Id: I03ce04ea6a24b84eeffd548d3f7bd306c58ce36d
Signed-off-by: Pierre Pfister <[email protected]>
src/vppinfra/format.c