\set ECHO none NOTICE: Inverse ranks increase at a centroid boundary NOTICE: Scalar and array inverse percentiles agree NOTICE: Inverse ranks increase at a centroid boundary NOTICE: Scalar and array inverse percentiles agree NOTICE: Inverse ranks increase at a centroid boundary NOTICE: Scalar and array inverse percentiles agree NOTICE: Inverse ranks increase at a centroid boundary NOTICE: Scalar and array inverse percentiles agree NOTICE: Equal-mean ranks follow the half-weight convention SET extra_float_digits = 2; -- The CDF used to decrease from 0.375 to 0.37499999999999994 just above 1. -- Both equal-mean centroids survive compaction at this compression. WITH ranks AS ( SELECT tdigest_percentile_of(d, 1::double precision) AS at_mean, tdigest_percentile_of(d, 1.0000000000000002::double precision) AS above_mean, tdigest_percentile_of(d, ARRAY[1, 1.0000000000000002]::double precision[]) AS array_ranks FROM (VALUES ( 'flags 1 count 36028797018963981 compression 10000 centroids 4 (0, 9007199254740995) (1, 2) (1, 9007199254740993) (10, 18014398509481991)'::tdigest )) AS input(d) ) SELECT at_mean, above_mean, array_ranks, at_mean <= above_mean AS monotone, array_ranks = ARRAY[at_mean, above_mean] AS scalar_array_agree FROM ranks; at_mean | above_mean | array_ranks | monotone | scalar_array_agree ---------------------+------------+-----------------------------+----------+-------------------- 0.37499999999999994 | 0.375 | {0.37499999999999994,0.375} | t | t (1 row) -- Preserve half-items without rounding the integer part and half separately. -- In particular, (double) (18014398509481987 / 2) + 0.5 double-rounds. WITH counts(n) AS ( VALUES (1::bigint), (3), (18014398509481987), (9223372036854775807) ) SELECT n, tdigest_percentile_of( format('flags 1 count %s compression 10000 centroids 1 (1, %s)', n, n)::tdigest, 1::double precision) AS rank FROM counts GROUP BY n ORDER BY n; n | rank ---------------------+------ 1 | 0.5 3 | 0.5 18014398509481987 | 0.5 9223372036854775807 | 0.5 (4 rows)