@@ -444,12 +444,29 @@ __mulodi4(di_int a, di_int b, int* overflow)
444444}
445445#endif
446446
447+ #if defined(__CYGWIN__) || defined(_WIN32)
448+ #define strcasecmp _stricmp
449+ #endif
450+
451+ static bool swift_stringIsSignalingNaN (const char *nptr) {
452+ if (nptr[0 ] == ' +' || nptr[0 ] == ' -' ) {
453+ nptr++;
454+ }
455+
456+ return strcasecmp (nptr, " snan" ) == 0 ;
457+ }
458+
447459#if defined(__CYGWIN__) || defined(_WIN32)
448460// Cygwin does not support uselocale(), but we can use the locale feature
449461// in stringstream object.
450462template <typename T>
451463static const char *_swift_stdlib_strtoX_clocale_impl (
452464 const char *nptr, T *outResult) {
465+ if (swift_stringIsSignalingNaN (nptr)) {
466+ *outResult = std::numeric_limits<T>::signaling_NaN ();
467+ return nptr + std::strlen (nptr);
468+ }
469+
453470 std::istringstream ValueStream (nptr);
454471 ValueStream.imbue (std::locale::classic ());
455472 T ParsedValue;
@@ -487,6 +504,13 @@ static const char *_swift_stdlib_strtoX_clocale_impl(
487504 const char * nptr, T* outResult, T huge,
488505 T (*posixImpl)(const char *, char **, locale_t )
489506) {
507+ if (swift_stringIsSignalingNaN (nptr)) {
508+ // TODO: ensure that the returned sNaN bit pattern matches that of sNaNs
509+ // produced by Swift.
510+ *outResult = std::numeric_limits<T>::signaling_NaN ();
511+ return nptr + std::strlen (nptr);
512+ }
513+
490514 char *EndPtr;
491515 errno = 0 ;
492516 const auto result = posixImpl (nptr, &EndPtr, getCLocale ());
0 commit comments