]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix loss of precision in pg_stat_us_to_ms()
authorJohn Naylor <john.naylor@postgresql.org>
Thu, 2 Jul 2026 06:26:56 +0000 (13:26 +0700)
committerJohn Naylor <john.naylor@postgresql.org>
Thu, 2 Jul 2026 06:26:56 +0000 (13:26 +0700)
Multiplying by the constant 0.001 can produce trailing-digit noise in
displayed values (for example 0.009000000000000001 instead of 0.009,
with default extra_float_digits) because 0.001 cannot be represented
exactly in binary floating point. Use division by 1000.0 instead,
matching code elsewhere in the tree.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Discussion: https://postgr.es/m/akIYkMK4bHe9qX/N@bdtpg

src/backend/utils/adt/pgstatfuncs.c

index 0c6a20843a501b25ad1233c659e681de699fbce7..b5f27b0463c864d08a4baeeb6abb163d9c29b38f 100644 (file)
@@ -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;
 }
 
 /*