Re: NaN divided by zero should yield NaN

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: NaN divided by zero should yield NaN
Date: 2020-07-17 18:08:53
Message-ID: CAEZATCX2-2doB6LTexN7LzAxQ6oSv2CbWZ=hCUqR-N2WN8n+zA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 16 Jul 2020 at 20:29, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Dean Rasheed questioned this longstanding behavior:
>
> regression=# SELECT 'nan'::float8 / '0'::float8;
> ERROR: division by zero
>
> After a bit of research I think he's right: per IEEE 754 this should
> yield NaN, not an error. Accordingly I propose the attached patch.
> This is probably not something to back-patch, though.
>

Agreed.

> One thing that's not very clear to me is which of these spellings
> is preferable:
>
> if (unlikely(val2 == 0.0) && !isnan(val1))
> if (unlikely(val2 == 0.0 && !isnan(val1)))
>

My guess is that the first would be better, since it would tell the
compiler that it's unlikely to need to do the NaN test, so it would be
kind of like doing

if (unlikely(val2 == 0.0))
if (!isnan(val1)))

Regards,
Dean

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2020-07-17 18:53:05 Re: renaming configure.in to configure.ac
Previous Message Tom Lane 2020-07-17 17:28:19 Re: Error during make, second install