Обсуждение: Re: [PATCHES] [BUGS] BUG #2846: inconsistent and confusing handling of underflows,

Поиск
Список
Период
Сортировка

Re: [PATCHES] [BUGS] BUG #2846: inconsistent and confusing handling of underflows,

От
Tom Lane
Дата:
Roman Kononov <kononov195-pgsql@yahoo.com> writes:
> On 12/27/2006 03:23 PM, Bruce Momjian wrote:
>> Are you sure?  As I remember, computation automatically upgrades to
>> 'double'.  See this program and output:

> This is platform- and compiler- dependent:

... and probably irrelevant, too.  We should store the result into a
float4 variable and then test for isinf() on that; that eliminates the
question of whether the compiler did the multiply in a wider format or
not.

            regards, tom lane

Re: [PATCHES] [BUGS] BUG #2846: inconsistent and confusing handling

От
Roman Kononov
Дата:
On 12/27/2006 05:19 PM, Tom Lane wrote:
> Roman Kononov <kononov195-pgsql@yahoo.com> writes:
>> On 12/27/2006 03:23 PM, Bruce Momjian wrote:
>>> Are you sure?  As I remember, computation automatically upgrades to
>>> 'double'.  See this program and output:
>
>> This is platform- and compiler- dependent:
>
> ... and probably irrelevant, too.  We should store the result into a
> float4 variable and then test for isinf() on that; that eliminates the
> question of whether the compiler did the multiply in a wider format or
> not.

You are right provided that you want to ignore underflows and silently
produce zeros instead.

If you go this way, I recommend to ignore overflows as well, and silently
produce infinities and NaNs.

Roman

Re: [PATCHES] [BUGS] BUG #2846: inconsistent and confusing

От
Bruce Momjian
Дата:
Tom Lane wrote:
> Roman Kononov <kononov195-pgsql@yahoo.com> writes:
> > On 12/27/2006 03:23 PM, Bruce Momjian wrote:
> >> Are you sure?  As I remember, computation automatically upgrades to
> >> 'double'.  See this program and output:
>
> > This is platform- and compiler- dependent:
>
> ... and probably irrelevant, too.  We should store the result into a
> float4 variable and then test for isinf() on that; that eliminates the
> question of whether the compiler did the multiply in a wider format or
> not.

True for overflow to Infinity, but underflow checking is better for
float4 using float8.  See previous email for details.

--
  Bruce Momjian   bruce@momjian.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

Re: [PATCHES] [BUGS] BUG #2846: inconsistent and confusing

От
Bruce Momjian
Дата:
Roman Kononov wrote:
> On 12/27/2006 05:19 PM, Tom Lane wrote:
> > Roman Kononov <kononov195-pgsql@yahoo.com> writes:
> >> On 12/27/2006 03:23 PM, Bruce Momjian wrote:
> >>> Are you sure?  As I remember, computation automatically upgrades to
> >>> 'double'.  See this program and output:
> >
> >> This is platform- and compiler- dependent:
> >
> > ... and probably irrelevant, too.  We should store the result into a
> > float4 variable and then test for isinf() on that; that eliminates the
> > question of whether the compiler did the multiply in a wider format or
> > not.
>
> You are right provided that you want to ignore underflows and silently
> produce zeros instead.
>
> If you go this way, I recommend to ignore overflows as well, and silently
> produce infinities and NaNs.

While IEEE seems fine with that, I don't think this is good for SQL.  It
is best to produce a meaningful error.  The major issue is that our
current code is buggy because it doesn't have consistent behavior, as
Roman outlined.

--
  Bruce Momjian   bruce@momjian.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +