Change nextafter and related functions to handle infinities as arguments the same way as GLIBC and MSVC. Fixes #5823.