NaN divided by zero should yield NaN
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Cc: Dean Rasheed <dean.a.rasheed@gmail.com>,
Andres Freund <andres@anarazel.de>
Date: 2020-07-16T19:29:45Z
Lists: pgsql-hackers
Attachments
- nan-over-zero-is-nan.patch (text/x-diff) patch
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. 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))) I think we can reject this variant: if (unlikely(val2 == 0.0) && unlikely(!isnan(val1))) since actually the second condition *is* pretty likely. But I don't know which of the first two would give better code. Andres, any thoughts? regards, tom lane
Commits
-
Make floating-point "NaN / 0" return NaN instead of raising an error.
- 4fb6aeb4f6e8 14.0 landed