Re: Arbitrary precision modulo operation

From: Harald Fuchs <hf320(at)protecting(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Arbitrary precision modulo operation
Date: 2004-04-27 13:19:41
Message-ID: puhdv5eexe.fsf@srv.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In article <408D4729(dot)303(at)yahoo(dot)com>,
Chadwick Boggs <chadwickboggs(at)yahoo(dot)com> writes:

> 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)

Is the name of the other, unnamed RDBMS by chance starting with an
'M'? ;-)

Anyway, both are wrong. According to GNU MP, the correct answer is
117. Thus PostgreSQL is at least almost right (117 - 123 = -6).

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2004-04-27 13:48:12 Re: shadowing (like IB/Firebird)
Previous Message Richard Huxton 2004-04-27 13:18:46 Re: questions on rules