diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc index 4a0cc9b984..fe37245d79 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/float.cc @@ -71,6 +71,7 @@ FloatFormat::FloatFormat(int4 sz) jbitimplied = true; } maxexponent = (1<getAttributeValue("jbitimplied")); maxexponent = (1<translate->getFloatFormat(sz); if (format == (const FloatFormat *)0) { - t << "FLOAT_UNKNOWN"; + token = "FLOAT_UNKNOWN"; } else { FloatFormat::floatclass type; double floatval = format->getHostFloat(val,&type); if (type == FloatFormat::infinity) { if (format->extractSign(val)) - t << '-'; - t << "INFINITY"; + token = "-INFINITY"; + else + token = "INFINITY"; } else if (type == FloatFormat::nan) { if (format->extractSign(val)) - t << '-'; - t << "NAN"; + token = "-NAN"; + else + token = "NAN"; } else { - if ((mods & force_scinote)!=0) + ostringstream t; + if ((mods & force_scinote)!=0) { t.setf( ios::scientific ); // Set to scientific notation - else - t.setf( ios::fixed ); // Otherwise use fixed notation - t.precision(8); // Number of digits of precision - t << floatval; + t.precision(format->getDecimalPrecision()-1); + t << floatval; + token = t.str(); + } + else { + // Try to print "minimal" accurate representation of the float + t.unsetf( ios::floatfield ); // Use "default" notation + t.precision(format->getDecimalPrecision()); + t << floatval; + token = t.str(); + bool looksLikeFloat = false; + for(int4 i=0;i