Re: Inconsistent shift operator

Поиск
Список
Период
Сортировка
От Sam Mason
Тема Re: Inconsistent shift operator
Дата
Msg-id 20080420133842.GN6870@frubble.xen.chris-lamb.co.uk
обсуждение исходный текст
Ответ на Re: Inconsistent shift operator  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Inconsistent shift operator  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
On Sat, Apr 19, 2008 at 11:26:57AM -0400, Tom Lane wrote:
> Roman Kononov <kononov@dls.net> writes:
> > The below test cases show the obvious inconsistency between different
> > integer types.
>
> [ shrug... ]  The << and >> operators just expose the behavior of the
> local C compiler's shift operators, and it's clearly stated in the C
> spec that shifting by more than the word width produces unspecified
> results.

I thought that getting the correct answer was more important than
getting the "wrong" answer quickly.  The current code also introduces
its own set of strangeness in the 16 bit case on my x86_64 box.  It does
something closer to:

  int16 shl (int val, int n) {
    n %= 32;
    return n < 16 ? val << n : 0;
  }

This is exactly what the code says, it's just the resulting semantics
aren't very nice for the user.

Wouldn't it be easy to put some code like this in:

  if (arg2 < 16)
    return PG_RETURN_INT16(arg1 << arg2);
  return PG_RETURN_INT16(0);

People would have one less platform specific weirdo to worry about.

As an aside, I thought it would be interesting to see what MySQL did and
it seems to check for and handle this case--albeit only the 64bit case,
but as far as I can tell it only really knows about "long long" ints.


  Sam

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

Предыдущее
От: Daniel Ruoso
Дата:
Сообщение: Re: BUG #4115: PostgreSQL ISO format is not really ISO
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: BUG #4115: PostgreSQL ISO format is not really ISO