On Fri, 25 Dec 2015 13:34:25 +0300
Teodor Sigaev <teodor@sigaev.ru> wrote:
> Thank you, but I have some notices about
> static float
> uuid_parts_distance(pg_uuid_t *a, pg_uuid_t *b)
> {
> pg_uuid_t ua, ub;
> const double mp = pow(2, -64);
>
> uuid_cnv(a, &ua);
> uuid_cnv(b, &ub);
>
> Assert(ua.v64[0] > ub.v64[0]);
> uint64 high = ua.v64[0] - ub.v64[0];
> uint64 low = ua.v64[1] - ub.v64[1];
> if (low > ua.v64[1])
> high--;
>
> return (float) (ldexp(high, 64) + (double) low * mp);
> }
>
> First, variables (high and low) should not be declared in the middle
> of code. Second, assert will fail if ua.v64[0] == ub.v64[0] and
> ua.v64[1] > ub.v64[1] although it's a possible and allowed case.
> Third, actually you multiply high value by 2^64 anf low by 2^-64.
> Seems, it's needed to do only one multiplication.
Thank you for review. Fixed.
--
Ildus Kurbangaliev
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company