Re: A few cases of left shifting negative integers

Поиск
Список
Период
Сортировка
От Andres Freund
Тема Re: A few cases of left shifting negative integers
Дата
Msg-id 20150821172329.GE8552@awork2.anarazel.de
обсуждение исходный текст
Ответ на Re: A few cases of left shifting negative integers  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: A few cases of left shifting negative integers  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On 2015-08-21 13:03:42 -0400, Tom Lane wrote:
> The behavior is well-defined, at least as long as we don't shift far
> enough to have integer overflow

Unfortunately not:
5.8.2: The value of E1 << E2 is E1 left-shifted E2 bit positions;
vacated bits are zero-filled. If E1 has an unsigned type, the value of
the result is E1 × 2 E2 , reduced modulo one more than the maximum value
representable in the result type. Otherwise, if E1 has a signed type and
non-negative value, and E1 × 2 E2 is representable in the result type,
then that is the resulting value; >>otherwise, the behavior is undefined<<.

See the >><< highlighted bit...



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

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: remove unused ExecGetScanType
Следующее
От: Tom Lane
Дата:
Сообщение: Re: A few cases of left shifting negative integers