1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-07 00:35:37 +02:00

Improve the predictability of floating point numbers formatted as strings.

Some C libraries (e.g.musl) render floating point numbers differently when using printf(). This does not cause any problems for the core code but the unit tests require more predictability to function smoothly without a lot of exceptions.

To accomplish this, wrap the various floating point operations in functions that mostly continue doing math using double but format the output string using integers. This leads to more predictable output at the cost of some complexity.

Rounding could also be accomplished using nearbyint() but this would require linking the math library, which does not seem worth it for a fairly simple operation.
This commit is contained in:
David Steele
2025-06-05 13:27:45 -04:00
committed by GitHub
parent a30442f168
commit ad7ba46bc6
22 changed files with 413 additions and 105 deletions

View File

@ -607,13 +607,13 @@ testRun(void)
" timestamp start/stop: 2018-11-16 15:47:56+00 / 2018-11-16 15:48:09+00\n"
" wal start/stop: n/a\n"
" database size: 25.7MB, database backup size: 25.7MB\n"
" repo1: backup set size: 3MB, backup size: 3KB\n"
" repo1: backup set size: 3MB, backup size: 3.1KB\n"
"\n"
" full backup: 20201116-154900F\n"
" timestamp start/stop: 2020-11-16 15:47:56+00 / 2020-11-16 15:48:00+00\n"
" wal start/stop: 000000030000000000000001 / 000000030000000000000001\n"
" database size: 25.7MB, database backup size: 25.7MB\n"
" repo1: backup set size: 3MB, backup size: 3KB\n",
" repo1: backup set size: 3MB, backup size: 3.1KB\n",
"text - single stanza, valid backup, no priors, no archives in latest DB, backup/expire lock detected");
// Notify child to release lock
@ -1530,7 +1530,7 @@ testRun(void)
TEST_RESULT_STR_Z(
infoRender(),
"stanza: stanza1\n"
" status: ok (backup/expire running - 65.27% complete)\n"
" status: ok (backup/expire running - 65.28% complete)\n"
" cipher: mixed\n"
" repo1: none\n"
" repo2: aes-256-cbc\n"