Re: pgsql: Remove unnecessary uses of Abs()

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: pgsql: Remove unnecessary uses of Abs()
Дата
Msg-id 11e02543-b480-cb6b-1271-6438841b1b8a@enterprisedb.com
обсуждение исходный текст
Ответ на Re: pgsql: Remove unnecessary uses of Abs()  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: pgsql: Remove unnecessary uses of Abs()  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-committers
On 07.10.22 16:38, Tom Lane wrote:
> Peter Eisentraut <peter@eisentraut.org> writes:
>> Remove unnecessary uses of Abs()
> 
> Re-reading this, I noticed something that's probably not good:
> in ecpg/pgtypeslib/interval.c you did
> 
> -           sprintf(cp, "%02d.%0*d", abs(sec), precision, (int) Abs(fsec));
> +           sprintf(cp, "%02d.%0*d", abs(sec), precision, abs(fsec));
> 
> (in 2 places).  I think this has possibly broken the direction of rounding
> for negative values, because we'll now truncate to integer before changing
> sign.  Maybe it's okay but you have to make assumptions about what it'll
> do.  Safer would have been
> 
> +           sprintf(cp, "%02d.%0*d", abs(sec), precision, (int) fabs(fsec));

fsec is of type fsec_t, which is int32.  So these expressions are 
integer all the way through.

> There is similar-looking coding in remove_gene(), but I didn't check
> the data type involved.

There, the type "Gene" is int, so also no floats involved AFAICT.




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

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: Fix self-referencing foreign keys with partitioned tables
Следующее
От: Tom Lane
Дата:
Сообщение: Re: pgsql: Remove unnecessary uses of Abs()