Re: [PATCH] expand the units that pg_size_pretty supports on output

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: David Christensen <david(dot)christensen(at)crunchydata(dot)com>, Shinya11(dot)Kato(at)nttdata(dot)com, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] expand the units that pg_size_pretty supports on output
Date: 2021-07-07 02:44:51
Message-ID: CAApHDvrXt8OgEBHX3FZrbmxLb=sxWFNe65g+4i3wYBxkLT6YvQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 7 Jul 2021 at 00:51, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2021-07-07 02:47:22 Re: [PATCH] expand the units that pg_size_pretty supports on output
Previous Message Bharath Rupireddy 2021-07-07 02:30:20 Re: Refactor "mutually exclusive options" error reporting code in parse_subscription_options