From: | "Dann Corbit" <DCorbit(at)connx(dot)com> |
---|---|
To: | "Paul Tillotson" <pntil(at)shentel(dot)net>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Arbitrary precision modulo operation |
Date: | 2004-04-27 00:46:23 |
Message-ID: | D90A5A6C612A39408103E6ECDD77B829408D6A@voyager.corporate.connx.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> -----Original Message-----
> From: Paul Tillotson [mailto:pntil(at)shentel(dot)net]
> Sent: Monday, April 26, 2004 4:41 PM
> To: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] Arbitrary precision modulo operation
>
>
> I see there are a few misconceptions about numeric and
> modulus on here:
>
> (1) A modulus operation on a numeric type should NOT have
> rounding errors. The whole point of numeric is that it is an
> arbitrary precision BASE 10 representation of your number.
This is true
> The modulus returns the (whole
> number) remainder as a result of a division.
This is true if the numeric values are integers.
When the values are not integral, some non-integral results can be
returned.
2.50 % 2.50 is 0
But 13.89 modulo 3.50 is 3.39
If you work it out on paper, you will see that 3.39 is the correct
remainder.
> (2) the modulus operator/function is, AFAIK, supposed to
> return the modulus with the SAME SIGN as the divisor, so I
> think this is a bug. That's what every other modulus operator
> that I have ever seen does. Would you mind doing
I would agree that a positive modulus is preferable. However, the
negative result is also mathematically correct.
> foodb=> SELECT version();
>
> (3) MySQL just rounds large numbers to the highest value that
> the type will support, and apparently, no arbitrary precision
> types are listed on this page:
>
> http://dev.mysql.com/doc/mysql/en/Numberic_type_overview.html
>
> You can't expect to get a modulus from an out-of-range number.
Should it not (therefore) throw an error of some sort?
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2004-04-27 01:48:44 | Re: 7.3.4 on Linux: UPDATE .. foo=foo+1 degrades massivly |
Previous Message | Paul Tillotson | 2004-04-26 23:41:16 | Re: Arbitrary precision modulo operation |