================
@@ -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).
----------------
conrade-ctc wrote:
@jcranmer-intel, nice, that's a more recent ref and mentions ryu, so i'll look
at that first and implement accordingly. thanks for pointing this out.
https://github.com/llvm/llvm-project/pull/218471
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits