Ref #14313: NaN detection. Close gh-1352.
(cherry picked from commit 0bc0a69026ce4c1ac570a729d3c975a4a55d0ff4)