Re: Arbitrary precision modulo operation - Mailing list pgsql-general

From Chadwick Boggs
Subject Re: Arbitrary precision modulo operation
Date
Msg-id 408D4729.303@yahoo.com
Whole thread Raw
In response to Arbitrary precision modulo operation  (Chadwick Boggs <chadwickboggs@yahoo.com>)
Responses Re: Arbitrary precision modulo operation
List pgsql-general
Example of wrong results from modulo operation of arbitrary precision
numbers:

# select '123456789012345678901234567890'::numeric % 123;
 ?column?
----------
       -6
(1 row)

# select mod('123456789012345678901234567890'::numeric, 123);
 mod
-----
  -6
(1 row)

The correct result (at least according to another, unnamed, RDBMS):

 > select '123456789012345678901234567890' % 123;
+----------------------------------------+
| '123456789012345678901234567890' % 123 |
+----------------------------------------+
|                                     58 |
+----------------------------------------+
1 row in set (0.00 sec)


Bruno Wolff III wrote:

>On Mon, Apr 26, 2004 at 10:18:52 -0400,
>  Chadwick Boggs <chadwickboggs@yahoo.com> wrote:
>
>
>>I need to perform modulo operations on extremely large numbers.  The %
>>operator is giving me number out of range errors and the mod(x, y)
>>function simply seems to return the wrong results.  Also, my numerator
>>is in the format of a quoted string, which the mod function can't take.
>>
>>
>
>How large is extremely large?
>You can cast the strings to a numeric type to solve the string problem.
>'numeric' should work for numbers up to about 1000 digits.
>For example:
>area=> select '1234567890'::numeric % '123'::numeric;
> ?column?
>----------
>       39
>(1 row)
>
>If you are getting wrong results you should post a specific example so
>that the developers can figure out what is going wrong.
>
>
>


pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: List Removal
Next
From: Andrew Ayers
Date:
Subject: Re: Installation Postgresql