

CREATE TABLE test_numeric_mul_rscale
(
    var1 numeric,
    var2 numeric,
    rscale_adjustment integer,
    expected numeric
);

CREATE TABLE test_numeric_power
(
    var1 numeric,
    var2 numeric,
    expected numeric
);

CREATE TABLE test_numeric_exp
(
    var numeric,
    expected numeric
);

\copy test_numeric_mul_rscale from test_numeric_mul_rscale.dump;
\copy test_numeric_power from test_numeric_power.dump;
\copy test_numeric_exp from test_numeric_exp.dump;

\x on

SELECT
    *,
    numeric_mul_rscale - expected AS diff
FROM
    test_numeric_mul_rscale,
    numeric_mul_rscale(var1, var2, rscale_adjustment)
WHERE numeric_mul_rscale IS DISTINCT FROM expected
ORDER BY rscale_adjustment DESC
LIMIT 1;

\x off

SELECT
    to_char(numeric_mul_rscale - expected,'0.000EEEE') AS diff,
    COUNT(*)
FROM
    test_numeric_mul_rscale,
    numeric_mul_rscale(var1, var2, rscale_adjustment)
GROUP BY diff
ORDER BY diff;

SELECT
    rscale_adjustment,
    COUNT(*)
FROM
    test_numeric_mul_rscale,
    numeric_mul_rscale(var1, var2, rscale_adjustment)
WHERE numeric_mul_rscale IS DISTINCT FROM expected
GROUP BY rscale_adjustment
ORDER BY rscale_adjustment;

\x on

SELECT
    *,
    numeric_power - expected AS diff
FROM
    test_numeric_power,
    numeric_power(var1, var2)
WHERE numeric_power IS DISTINCT FROM expected
LIMIT 1;

\x on

SELECT
    *,
    numeric_exp - expected AS diff
FROM
    test_numeric_exp,
    numeric_exp(var)
WHERE numeric_exp IS DISTINCT FROM expected
LIMIT 1;
