Fix sscanf/wcstod parsing of NaNs.

The parsefloat routines -- which let us pass NaNs and infinities on to
strto(f|d|ld) -- come from NetBSD.

Also fix LP64's strtold to return a NaN, and fix all the architectures
to return quiet NaNs.

Also fix wcstof/wcstod/wcstold to use parsefloat so they support hex
floats.

Lots of new tests.

Bug: http://b/31101647
Change-Id: Id7d46ac2d8acb8770b5e8c445e87cfabfde6f111
diff --git a/tests/math_data_test.h b/tests/math_data_test.h
index 0aba701..42dc42c 100644
--- a/tests/math_data_test.h
+++ b/tests/math_data_test.h
@@ -16,6 +16,7 @@
 
 #include <gtest/gtest.h>
 
+#include <math.h>
 #include <fenv.h>
 
 template <typename RT, typename T1>
@@ -102,7 +103,28 @@
   uint64_t sign_magnitude;
 };
 
-// TODO: long double.
+template <> union fp_u<long double> {
+  long double value;
+#if defined(__LP64__)
+  struct {
+    unsigned fracl;
+    unsigned fraclm;
+    unsigned frachm;
+    unsigned frach:16;
+    unsigned exp:15;
+    unsigned sign:1;
+  } bits;
+  __int128_t sign_magnitude;
+#else
+  struct {
+      unsigned fracl;
+      unsigned frach:20;
+      unsigned exp:11;
+      unsigned sign:1;
+  } bits;
+  uint64_t sign_magnitude;
+#endif
+};
 
 template <typename T>
 static inline auto SignAndMagnitudeToBiased(const T& value) -> decltype(fp_u<T>::sign_magnitude) {
@@ -134,14 +156,8 @@
       return ::testing::AssertionSuccess();
     }
 
-    // Output the actual and expected values as hex floating point.
-    char expected_str[64];
-    char actual_str[64];
-    snprintf(expected_str, sizeof(expected_str), "%a", expected);
-    snprintf(actual_str, sizeof(actual_str), "%a", actual);
-
     return ::testing::AssertionFailure()
-        << "expected (" << expected_str << ") != actual (" << actual_str << ")";
+        << "expected (" << std::hexfloat << expected << ") != actual (" << actual << ")";
   }
 };
 
@@ -282,4 +298,3 @@
                         data[i].expected, f(data[i].input1, data[i].input2, data[i].input3)) << "Failed on element " << i;
   }
 }
-