Fixed #23770 -- Changed serialization strategy for floats with respect to NaN and Inf

Thanks to w0rp for the report
Why did you move this to a separate block?