Purpose of rscale/dscale in NUMERIC? - Mailing list pgsql-hackers

From Tom Lane
Subject Purpose of rscale/dscale in NUMERIC?
Date
Msg-id 17150.1033507490@sss.pgh.pa.us
Whole thread Raw
List pgsql-hackers
What is the reason for maintaining separate rscale and dscale values in
numeric variables?

I am finding that this arrangement leads to some odd results, for
example this:

regression=# select (exp(ln(2.0)) - 2.0);     ?column?
----------------------0.0000000000000000
(1 row)

regression=# select (exp(ln(2.0)) - 2.0) * 100000;     ?column?
----------------------0.0000000000000010
(1 row)

The difference between rscale and dscale allows some "hidden" digits to
be carried along in an expression result, and then possibly exposed
later.  This seems pretty nonintuitive for an allegedly exact
calculational datatype.  ISTM the policy should be "what you see is what
you get" - no hidden digits.  That would mean there's no need for
separating rscale and dscale, so I'm wondering why they were put in
to begin with.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: table lock and record lock
Next
From: "scott.marlowe"
Date:
Subject: Re: table lock and record lock