atilaneves / unit-threaded

Advanced unit test framework for D
BSD 3-Clause "New" or "Revised" License
122 stars 38 forks source link

Full precision formatting is desirable for floating point numbers #284

Closed 9il closed 1 year ago

9il commented 1 year ago

It is essential to see the whole number when debugging numeric algorithms.

atilaneves commented 1 year ago

Unless you give me an example of what happens now and what should happen instead, I don't know how I can fix this.

9il commented 1 year ago

It would be much more helpfull to print floating points in assert messages of should and shouldApproxEqual in sciencific notation with 16 decimal points after the dot using C library. Phobos gives wrong results (if it doesn't use C library for sciencific notation, I am not sure about if it is). Ofcourse, you are wellcome to use Mir's to!string, it will give the full precision in minimal form. C's sciencific notation is good too.

9il commented 1 year ago

Unitthreaded example:

unittest
{
    import unit_threaded;
    auto a = 1e-7;
    a.shouldApproxEqual(0, 1e-8, 1e-8);
}
unit_threaded.exception.UnitTestException@source/mir/complex/math.d(376): Expected approx: 0
     Got       : 0.000000

The same example with mir.test

unittest 
{
    import mir.test;
    auto a = 1e-7;
    a.shouldApprox(1e-8, 1e-8) == 0;
}
mir.exception.MirError@source/mir/date.d(4473): expected approximately 0.0, got 1e-7, maxRelDiff = 1e-8, maxAbsDiff = 1e-8