Re: Avoiding roundoff error in pg_sleep() - Mailing list pgsql-hackers

From Robert Haas
Subject Re: Avoiding roundoff error in pg_sleep()
Date
Msg-id CA+TgmoanvqTwQihU7ByWu+xWt8tjbUfpKV_8y=9iT09Ysw-q=w@mail.gmail.com
Whole thread Raw
In response to Avoiding roundoff error in pg_sleep()  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Avoiding roundoff error in pg_sleep()
List pgsql-hackers
On Thu, Sep 25, 2025 at 2:42 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> I chanced to notice that if you ask pg_sleep for 1ms delay,
> what you actually get is 2ms, for example

Oh, wow. I tested and I get the same behavior.

> Anyway, I propose trying to get rid of this misbehavior by avoiding
> floating point in the delay computation, as attached.

Score one for my blind yet fiery hatred of floating-point arithmetic.
The patch looks good except that (places tongue firmly in cheek) it
will cause problems for users who want to sleep for more than 150,000
years.

--
Robert Haas
EDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Avoiding roundoff error in pg_sleep()
Next
From: Tom Lane
Date:
Subject: Re: Avoiding roundoff error in pg_sleep()