Re: [PATCH] expand the units that pg_size_pretty supports on output - Mailing list pgsql-hackers

From David Rowley
Subject Re: [PATCH] expand the units that pg_size_pretty supports on output
Date
Msg-id CAApHDvrXt8OgEBHX3FZrbmxLb=sxWFNe65g+4i3wYBxkLT6YvQ@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] expand the units that pg_size_pretty supports on output  (Dean Rasheed <dean.a.rasheed@gmail.com>)
List pgsql-hackers
On Wed, 7 Jul 2021 at 00:51, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
> 10. half_round(21) == 11 :: 20 >> 1 = 10
>
> The correct result should be 10 (it would be very odd to claim that
> 10241 bytes should be displayed as 11kb), but the half-rounding keeps
> rounding up at each stage.
>
> That's a general property of rounding -- you need to be very careful
> when rounding more than once, since otherwise errors will propagate.
> C.f. 4083f445c0, which removed a double-round in numeric sqrt().

Thanks. I've adjusted the patch to re-add the round bool flag and get
rid of the rightShift field.  I'm now calculating how many bits to
shift right by based on the difference between the unitbits of the
current and next unit then taking 1 bit less if the next unit does
half rounding and the current one does not, or adding an extra bit on
in the opposite case.

I'll post another patch shortly.

David



pgsql-hackers by date:

Previous
From: Bharath Rupireddy
Date:
Subject: Re: Refactor "mutually exclusive options" error reporting code in parse_subscription_options
Next
From: David Rowley
Date:
Subject: Re: [PATCH] expand the units that pg_size_pretty supports on output