forked from OSchip/llvm-project
[flang] Make it easier to enable minimal FP output by default for module files (but do not enable it)
Original-commit: flang-compiler/f18@f6b640319b Reviewed-on: https://github.com/flang-compiler/f18/pull/671
This commit is contained in:
parent
b7d463f1d5
commit
9717cc43b8
|
@ -459,7 +459,8 @@ std::string Real<W, P, IM>::DumpHexadecimal() const {
|
|||
}
|
||||
|
||||
template<typename W, int P, bool IM>
|
||||
std::ostream &Real<W, P, IM>::AsFortran(std::ostream &o, int kind) const {
|
||||
std::ostream &Real<W, P, IM>::AsFortran(
|
||||
std::ostream &o, int kind, bool minimal) const {
|
||||
if (IsNotANumber()) {
|
||||
o << "(0._" << kind << "/0.)";
|
||||
} else if (IsInfinite()) {
|
||||
|
@ -476,8 +477,11 @@ std::ostream &Real<W, P, IM>::AsFortran(std::ostream &o, int kind) const {
|
|||
using B = decimal::BinaryFloatingPointNumber<P>;
|
||||
const auto *value{reinterpret_cast<const B *>(this)};
|
||||
char buffer[24000]; // accommodate real*16
|
||||
auto result{decimal::ConvertToDecimal<P>(buffer, sizeof buffer,
|
||||
static_cast<decimal::DecimalConversionFlags>(0),
|
||||
decimal::DecimalConversionFlags flags{}; // default: exact representation
|
||||
if (minimal) {
|
||||
flags = decimal::Minimize;
|
||||
}
|
||||
auto result{decimal::ConvertToDecimal<P>(buffer, sizeof buffer, flags,
|
||||
static_cast<int>(sizeof buffer), decimal::RoundNearest, *value)};
|
||||
const char *p{result.str};
|
||||
if (DEREF(p) == '-' || *p == '+') {
|
||||
|
|
|
@ -362,7 +362,7 @@ public:
|
|||
|
||||
// Emits a character representation for an equivalent Fortran constant
|
||||
// or parenthesized constant expression that produces this value.
|
||||
std::ostream &AsFortran(std::ostream &, int kind) const;
|
||||
std::ostream &AsFortran(std::ostream &, int kind, bool minimal = false) const;
|
||||
|
||||
private:
|
||||
using Significand = Integer<significandBits>; // no implicit bit
|
||||
|
|
|
@ -164,7 +164,7 @@ template<typename R> void basicTests(int rm, Rounding rounding) {
|
|||
MATCH(x, ivf.value.ToUInt64())(ldesc);
|
||||
if (rounding.mode == RoundingMode::TiesToEven) { // to match stold()
|
||||
std::stringstream ss;
|
||||
vr.value.AsFortran(ss, kind);
|
||||
vr.value.AsFortran(ss, kind, false /*exact*/);
|
||||
std::string decimal{ss.str()};
|
||||
const char *p{decimal.data()};
|
||||
MATCH(x, static_cast<std::uint64_t>(std::stold(decimal)))
|
||||
|
@ -411,7 +411,7 @@ void subsetTests(int pass, Rounding rounding, std::uint32_t opds) {
|
|||
|
||||
static constexpr int kind{REAL::bits / 8};
|
||||
std::stringstream ss, css;
|
||||
x.AsFortran(ss, kind);
|
||||
x.AsFortran(ss, kind, false /*exact*/);
|
||||
std::string s{ss.str()};
|
||||
if (IsNaN(rj)) {
|
||||
css << "(0._" << kind << "/0.)";
|
||||
|
|
Loading…
Reference in New Issue