[lldb-dev] [llvm] r189624 - Change default # of digits for APFloat::toString

Greg Clayton gclayton at apple.com
Thu Sep 5 13:48:57 PDT 2013


I agree here that floating point numbers should never be watered down when displaying them, we should always print out the most accurate version of it. For tests that want an exact number, use a number that works well for floating point like any negative power of 2 (0.5, .25, .125, etc). Numbers like 1.25 will always be able to be perfectly represented, so I would fix the test cases to use better numbers.

Greg

On Sep 5, 2013, at 1:37 PM, Eli Friedman <eli.friedman at gmail.com> wrote:

> On Wed, Sep 4, 2013 at 7:21 AM, Thirumurthi, Ashok <ashok.thirumurthi at intel.com> wrote:
> Hi Eli,
> 
> I noticed that your commit introduces a regression in the LLDB test suite because expression evaluation of a floating point constant like 2.234f results in a value like 2.23399997.  I suspect that this occurs because 2.234f is really just the closest number to 2.23399997 that can be represented using floating point precision.  I noticed that your commit increases the default number of digits in the precision of APFloat.  I can see how that's useful when performing intermediate computation, but I would have expected APFloat::toString to cleverly avoid reality.
> 
> The attached black magic fixes the regressions in the IRInterpreter used for expression evaluation.  However, I'm wondering if the correct fix is to revert your commit (i.e. in favor of mode to select the default precision as nominal precision versus active precision).  Cheers,
> 
> 
> What APFloat::toString really needs to do by default is consistently print the least number of digits necessary to re-parse to the same value.  Using a fixed number of digits is never going to what we want.  Unfortunately, that patch is a lot more complicated, and I don't really have the time or expertise to push it through.  If you're interested, I've attached my work-in-progress, based on the Dragon4 algorithm from "How to Print Floating-Point Numbers Accurately" by Steele and White.
> 
> -Eli
> <floattostringwip.txt>_______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev




More information about the lldb-dev mailing list