Re: Add numeric_trim(numeric) - Mailing list pgsql-hackers

From Dean Rasheed
Subject Re: Add numeric_trim(numeric)
Date
Msg-id CAEZATCWE+CRT94A6wvW0Fd=kzXssa=TDxvLJw=FPYf47yOqYsA@mail.gmail.com
Whole thread Raw
In response to Re: Add numeric_trim(numeric)  (Dean Rasheed <dean.a.rasheed@gmail.com>)
List pgsql-hackers
On 6 January 2016 at 15:21, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
> Actually I found the implementation a little confusing, partly because
> the first comment doesn't really match the line of code that follows
> it, and partly because of the complexity of the loop, the macros and
> working out all the exit conditions from the loop. A much simpler
> implementation would be to first call strip_var() ...

Additionally, the central part of the algorithm where it computes dig
% 10, dig % 100 and dig % 1000 inside a bunch of conditional macros is
overly complex and hard to read. Once you've got it down to the case
where you know dig is non-zero, you can just do

while ((dig % 10) == 0)
{   dscale--;   dig /= 10;
}

which works for any NBASE, rather than having to introduce an
NBASE-dependent block of code with all those preprocessor
conditionals.

(Actually, given the other thread of this discussion, I would name
that local variable min_scale now.)

Regards,
Dean



pgsql-hackers by date:

Previous
From: Craig Ringer
Date:
Subject: Re: pglogical - logical replication contrib module
Next
From: Ashutosh Bapat
Date:
Subject: Re: Getting sorted data from foreign server for merge join