The following bug has been logged on the website:
Bug reference: 17876
Logged by: Mats Kindahl
Email address: mats@timescale.com
PostgreSQL version: 15.2
Operating system: All
Description:
On 64-bit platforms, the existing width_bucket() computation can
result in a NaN (0x8000000) if the difference between the `operand`,
`low`, or `high` parameters exceeds DBL_MAX. This is then cast to the
value -2147483648.
mats=# WITH sample(operand, low, high, cnt) AS (
VALUES
(10.5::float8, -1.797e+308::float8, 1.797e+308::float8, 1::int4),
(10.5::float8, -1.797e+308::float8, 1.797e+308::float8, 2),
(10.5::float8, -1.797e+308::float8, 1.797e+308::float8, 3),
(1.797e+308::float8 / 2, -1.797e+308::float8, 1.797e+308::float8, 10),
(-1.797e+308::float8 / 2, -1.797e+308::float8, 1.797e+308::float8, 10),
(1.797e+308::float8 / 2, -1.797e+308::float8, 1.797e+308::float8, 16),
(-1.797e+308::float8 / 2, -1.797e+308::float8, 1.797e+308::float8, 16),
(1.797e+308::float8, -1.797e+308::float8 / 2, 1.797e+308::float8 / 2,
10),
(-1.797e+308::float8, -1.797e+308::float8 / 2, 1.797e+308::float8 / 2,
10)
) SELECT width_bucket(operand, low, high, cnt) FROM sample;
width_bucket
--------------
1
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
-2147483648
11
0
(9 rows)