Commits

Bryan O'Sullivan  committed c557bee

Use our own converter that doesn't need to follow JS rules.

  • Participants
  • Parent commits 3bebbf9

Comments (0)

Files changed (1)

File cbits/hs-double-conversion.cc

   return pos;
 }
 
+static inline const DoubleToStringConverter& defaultConverter(void)
+{
+  const int flags = DoubleToStringConverter::UNIQUE_ZERO;
+  static DoubleToStringConverter converter(flags,
+                                           "Infinity",
+                                           "NaN",
+                                           'e',
+                                           -6, 21,
+                                           6, 0);
+  return converter;
+}
+
 extern "C"
 int _hs_ToShortest(double value, uint16_t *buf)
 {
-  const DoubleToStringConverter& converter =
-    DoubleToStringConverter::EcmaScriptConverter();
   char cbuf[kToShortestLength];
-
   StringBuilder builder(cbuf, kToShortestLength);
-  bool ok = converter.ToShortest(value, &builder);
+  bool ok = defaultConverter().ToShortest(value, &builder);
 
   if (!ok)
     return -1;
 extern "C"
 int _hs_ToFixed(double value, uint16_t *buf, const int ndigits)
 {
-  const DoubleToStringConverter& converter =
-    DoubleToStringConverter::EcmaScriptConverter();
   char cbuf[kToFixedLength];
-
   StringBuilder builder(cbuf, kToFixedLength);
-  bool ok = converter.ToFixed(value, ndigits, &builder);
+  bool ok = defaultConverter().ToFixed(value, ndigits, &builder);
 
   if (!ok)
     return -1;
 extern "C"
 int _hs_ToExponential(double value, uint16_t *buf, const int ndigits)
 {
-  const DoubleToStringConverter& converter =
-    DoubleToStringConverter::EcmaScriptConverter();
   char cbuf[kToExponentialLength];
-
   StringBuilder builder(cbuf, kToExponentialLength);
-  bool ok = converter.ToExponential(value, ndigits, &builder);
+  bool ok = defaultConverter().ToExponential(value, ndigits, &builder);
 
   if (!ok)
     return -1;
 extern "C"
 int _hs_ToPrecision(double value, uint16_t *buf, const int precision)
 {
-  const DoubleToStringConverter& converter =
-    DoubleToStringConverter::EcmaScriptConverter();
   char cbuf[kToPrecisionLength];
-
   StringBuilder builder(cbuf, kToPrecisionLength);
-  bool ok = converter.ToPrecision(value, precision, &builder);
+  bool ok = defaultConverter().ToPrecision(value, precision, &builder);
 
   if (!ok)
     return -1;