================
@@ -5973,6 +5974,43 @@ APFloat APFloat::getAllOnesValue(const fltSemantics 
&Semantics) {
   return APFloat(Semantics, APInt::getAllOnes(Semantics.sizeInBits));
 }
 
+bool APFloat::toStringRoundTrip(SmallVectorImpl<char> &Str,
+                                unsigned FormatPrecision,
+                                unsigned FormatMaxPadding,
+                                bool TruncateZero) const {
+  SmallString<32> Buf;
+  toString(Buf, FormatPrecision, FormatMaxPadding, TruncateZero);
+  Str.append(Buf.begin(), Buf.end());
+  APFloat Parsed(getSemantics());
+  Expected<opStatus> Status =
+      Parsed.convertFromString(Buf, rmNearestTiesToEven);
+  if (!Status) {
+    consumeError(Status.takeError());
+    return false;
+  }
+  return Parsed.bitwiseIsEqual(*this);
+}
+
+void APFloat::toStringShortest(SmallVectorImpl<char> &Str,
+                               unsigned FormatMaxPadding,
+                               bool TruncateZero) const {
+  SmallString<32> Best;
+  toString(Best, /*FormatPrecision=*/0, FormatMaxPadding, TruncateZero);
+  if (isFiniteNonZero()) {
+    // Probe below the conservative natural precision (toStringImpl's FIXME).
----------------
jcranmer-intel wrote:

I do agree that this is a terribly inefficient implementation; the best 
algorithm right now I think is Dragonbox: 
https://github.com/jk-jeon/dragonbox/blob/master/other_files/Dragonbox.pdf

(see also https://onlinelibrary.wiley.com/doi/epdf/10.1002/spe.70056 for 
empirical testing).

https://github.com/llvm/llvm-project/pull/218471
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to