Encode "inf" and "nan" values as strings.