agora inbox for [email protected]
help / color / mirror / Atom feedFrom: Bertrand Drouvot <[email protected]>
Subject: [PATCH v1] Fix floating-point noise in pg_stat_us_to_ms()
Date: Mon, 29 Jun 2026 06:31:58 +0000
Multiplying by 0.001 can produce trailing-digit noise in displayed
values (for example 0.009000000000000001 instead of 0.009, should extra_float_digits
not being set to 0) because 0.001 cannot be represented exactly in binary floating
point.
Use division by 1000.0 instead as it is the most common way to deal with such
computation in the code tree.
Author: Bertrand Drouvot <[email protected]>
---
src/backend/utils/adt/pgstatfuncs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
100.0% src/backend/utils/adt/
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 6f9c9c72de5..1e5f8293b28 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -1457,7 +1457,7 @@ pgstat_get_io_time_index(IOOp io_op)
static inline double
pg_stat_us_to_ms(PgStat_Counter val_ms)
{
- return val_ms * (double) 0.001;
+ return (double) val_ms / 1000.0;
}
/*
--
2.34.1
--TXuqZKQhWXLuSKvO--
view thread (15+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [PATCH v1] Fix floating-point noise in pg_stat_us_to_ms()
In-Reply-To: <no-message-id-657466@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox