it seems boost::lexical_cast does not recognize "nan" or "NaN" in older versions and throws a boost::bad_lexical_cast. To be consistent, we can catch the error, check for these three cases and return isnan or throw a ConversionError if the String is none of these.