Re: Arbitrary precision modulo operation

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Chadwick Boggs <chadwickboggs(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Arbitrary precision modulo operation
Date: 2004-04-26 17:23:37
Message-ID: 20040426172337.GC18684@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Apr 26, 2004 at 10:18:52 -0400,
Chadwick Boggs <chadwickboggs(at)yahoo(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chadwick Boggs 2004-04-26 17:30:17 Re: Arbitrary precision modulo operation
Previous Message Andrew Ayers 2004-04-26 17:22:36 Re: Installation Postgresql