Re: add modulo (%) operator to pgbench

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: add modulo (%) operator to pgbench
Дата
Msg-id 20268.1411581222@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: add modulo (%) operator to pgbench  (Kevin Grittner <kgrittn@ymail.com>)
Список pgsql-hackers
Kevin Grittner <kgrittn@ymail.com> writes:
> Assuming that all values are integers, for:

>   x = a / b;
>   y = a % b;

>   If b is zero either statement must generate an error.
>   If a and b have the same sign, x must be positive; else x must be negative.
>   It must hold that abs(x) is equal to abs(a) / abs(b).
>   It must hold that ((x * b) + y) is equal to a.

Not sure about the third of those statements, but the last one is
definitely a requirement.

I think the only defensible choice, really, is that % should be defined
so that a = ((a / b) * b) + (a % b).  It is perfectly reasonable to
provide other division/modulus semantics as functions, preferably in
matching pairs that also satisfy this axiom.  But the two operators need
to agree, or you'll have surprised users.
        regards, tom lane



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Kevin Grittner
Дата:
Сообщение: Re: add modulo (%) operator to pgbench
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: Re: better atomics - v0.6