Re: pgsql: Ensure that numeric.c compiles with other NBASE values.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: pgsql: Ensure that numeric.c compiles with other NBASE values.
Дата
Msg-id 1604326.1675387093@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: pgsql: Ensure that numeric.c compiles with other NBASE values.  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Ответы Re: pgsql: Ensure that numeric.c compiles with other NBASE values.  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Список pgsql-committers
Dean Rasheed <dean.a.rasheed@gmail.com> writes:
> However, looking more closely, I think this function is more or less
> completely broken:

> 1). It doesn't work if log10val2 < 0, because then m < 0, and it
> doesn't multiply by the remainder. And it then throws an overflow
> error, because result.dscale comes out wrong when m < 0.

> 2). The result.dscale calculation is wrong if log10val2 is a multiple
> of DEC_DIGITS, causing it to drop the last 4 digits.

> 3). If the scaled-up dividend doesn't fit in an int64, the numeric
> computation breaks if log10val2 >= 10 due to integer overflow.

Ugh.

I'm not quite sure that it's worth expending code space on the
log10val2 < 0 case (compared to just "Assert(log10val2 >= 0").
On the other hand, it's not much extra code, and committing it now
might save somebody reinventing that logic in future.

I've not actually tested the patch, but it looks reasonable
by eyeball.

            regards, tom lane



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

Предыдущее
От: Dean Rasheed
Дата:
Сообщение: Re: pgsql: Ensure that numeric.c compiles with other NBASE values.
Следующее
От: Thomas Munro
Дата:
Сообщение: pgsql: ci: Upgrade macOS version from 12 to 13.