Re: NaN divided by zero should yield NaN
Dean Rasheed <dean.a.rasheed@gmail.com>
From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
Andres Freund <andres@anarazel.de>
Date: 2020-07-17T18:08:53Z
Lists: pgsql-hackers
On Thu, 16 Jul 2020 at 20:29, Tom Lane <tgl@sss.pgh.pa.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
Commits
-
Make floating-point "NaN / 0" return NaN instead of raising an error.
- 4fb6aeb4f6e8 14.0 landed