- }
-#elif defined(HAS_STRTOD)
- if (INFNAN_PEEK(s, send)) {
- /* The native strtod() may not get all the possible
- * inf/nan strings INFNAN_PEEK() recognizes. */
- char* endp;
- NV nv = Perl_strtod(p, &endp);
- if (p != endp) {
- *value = nv;
- return endp;
+#endif
+#ifdef Perl_strtod
+ /* If still here, we didn't have either NV_INF or INV_NAN,
+ * and can try falling back to native strtod/strtold.
+ *
+ * The native interface might not recognize all the possible
+ * inf/nan strings Perl recognizes. What we can try
+ * is to try faking the input. We will try inf/-inf/nan
+ * as the most promising/portable input. */
+ {
+ const char* fake = NULL;
+ char* endp;
+ NV nv;
+ if ((infnan & IS_NUMBER_INFINITY)) {
+ fake = ((infnan & IS_NUMBER_NEG)) ? "-inf" : "inf";
+ }
+ else if ((infnan & IS_NUMBER_NAN)) {
+ fake = "nan";
+ }
+ assert(fake);
+ nv = Perl_strtod(fake, &endp);
+ if (fake != endp) {
+ if ((infnan & IS_NUMBER_INFINITY)) {
+#ifdef Perl_isinf
+ if (Perl_isinf(nv))
+ *value = nv;
+#else
+ /* last resort, may generate SIGFPE */
+ *value = Perl_exp((NV)1e9);
+ if ((infnan & IS_NUMBER_NEG))
+ *value = -*value;
+#endif
+ return (char*)p; /* p, not endp */
+ }
+ else if ((infnan & IS_NUMBER_NAN)) {
+#ifdef Perl_isnan
+ if (Perl_isnan(nv))
+ *value = nv;
+#else
+ /* last resort, may generate SIGFPE */
+ *value = Perl_log((NV)-1.0);
+#endif
+ return (char*)p; /* p, not endp */
+ }
+ }