Ignore:
Timestamp:
11/25/18 20:13:18 (5 years ago)
Author:
Maciej Komosinski
Message:

Used the Dragon4 algorithm to print floating point values with full precision instead of "%.17g"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/sstring-simple.cpp

    r793 r826  
    33#include "extvalue.h"
    44#include <assert.h>
     5#ifdef USE_PRINTFLOAT_DRAGON4
     6#include <PrintFloat/PrintFloat.h>
     7#endif
    58
    69void SString::initEmpty()
     
    224227SString SString::valueOf(double d)
    225228{
    226         SString tmp = SString::sprintf("%.15g", d);
     229#ifdef USE_PRINTFLOAT_DRAGON4
     230        SString tmp;
     231        char* here = tmp.directWrite(30);
     232        tmp.endWrite(PrintFloat64(here, 30, d,
     233                ((d < -1e17) || (d > 1e17) || ((d < 1e-4) && (d > -1e-4) && (d != 0.0)))
     234                ? PrintFloatFormat_Scientific : PrintFloatFormat_Positional,
     235                -1));//http://www.ryanjuckett.com/programming/printing-floating-point-numbers/
     236#else
     237        SString tmp = SString::sprintf("%.17g", d); //https://stackoverflow.com/questions/16839658/printf-width-specifier-to-maintain-precision-of-floating-point-value
     238#endif
    227239        if ((!strchr(tmp.c_str(), '.')) && (!strchr(tmp.c_str(), 'e'))) tmp += ".0";
    228240        return tmp;
Note: See TracChangeset for help on using the changeset viewer.