Changeset 826


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

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

Location:
cpp/frams
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/Makefile-SDK-files

    r800 r826  
    22
    33# ALL_DIRS is later expanded by the shell, no spaces/newlines allowed, or it breaks
    4 ALL_DIRS={common,frams,frams/canvas,frams/config,common/loggers,frams/genetics,frams/genetics/f0,frams/genetics/f1,frams/genetics/f2,frams/genetics/f3,frams/genetics/f4,frams/genetics/f5,frams/genetics/f6,frams/genetics/f7,frams/genetics/f8,frams/genetics/f9,frams/genetics/fn,frams/genetics/fF,frams/genetics/fT,frams/genetics/fB,frams/genetics/fH,frams/genetics/fL,frams/model,frams/neuro,frams/neuro/impl,frams/param,frams/test,frams/util,frams/vm/classes,common/virtfile,frams/_demos,frams/model/geometry,frams/_demos/geometry,frams/model/similarity,frams/model/similarity/SVD}
     4ALL_DIRS={common,PrintFloat,frams,frams/canvas,frams/config,common/loggers,frams/genetics,frams/genetics/f0,frams/genetics/f1,frams/genetics/f2,frams/genetics/f3,frams/genetics/f4,frams/genetics/f5,frams/genetics/f6,frams/genetics/f7,frams/genetics/f8,frams/genetics/f9,frams/genetics/fn,frams/genetics/fF,frams/genetics/fT,frams/genetics/fB,frams/genetics/fH,frams/genetics/fL,frams/model,frams/neuro,frams/neuro/impl,frams/param,frams/test,frams/util,frams/vm/classes,common/virtfile,frams/_demos,frams/model/geometry,frams/_demos/geometry,frams/model/similarity,frams/model/similarity/SVD}
    55
    66GENMANF4=frams/genetics/f4/f4_oper.o
     
    2929GENMAN_COMMON_OBJS=frams/genetics/genman.o frams/param/mutableparam.o frams/param/mutparamlist.o frams/neuro/geneticneuroparam.o frams/neuro/neurolibparam.o
    3030
    31 SDK_OBJS=frams/util/list.o frams/util/advlist.o frams/param/param.o frams/util/sstring.o frams/util/sstringutils.o frams/util/3d.o frams/vm/classes/3dobject.o frams/model/model.o frams/model/modelparts.o frams/neuro/neurolibrary.o frams/genetics/geno.o frams/genetics/genoconv.o frams/util/extvalue.o frams/vm/classes/collectionobj.o frams/util/hashtable.o common/log.o common/stl-util.o common/nonstd_stdio.o frams/util/callbacks.o frams/param/syntparam.o frams/util/multirange.o frams/util/multimap.o frams/param/paramtabobj.o common/loggers/loggers.o frams/param/paramobj.o frams/genetics/genooperators.o common/nonstd_math.o frams/util/validitychecks.o common/Convert.o frams/util/rndutil.o common/virtfile/stringfile.o
     31PRINTFLOAT_OBJS=PrintFloat/Math.o PrintFloat/Dragon4.o PrintFloat/PrintFloat.o
     32
     33SDK_OBJS=frams/util/list.o frams/util/advlist.o frams/param/param.o frams/util/sstring.o frams/util/sstringutils.o frams/util/3d.o frams/vm/classes/3dobject.o frams/model/model.o frams/model/modelparts.o frams/neuro/neurolibrary.o frams/genetics/geno.o frams/genetics/genoconv.o frams/util/extvalue.o frams/vm/classes/collectionobj.o frams/util/hashtable.o common/log.o common/stl-util.o common/nonstd_stdio.o frams/util/callbacks.o frams/param/syntparam.o frams/util/multirange.o frams/util/multimap.o frams/param/paramtabobj.o common/loggers/loggers.o frams/param/paramobj.o frams/genetics/genooperators.o common/nonstd_math.o frams/util/validitychecks.o common/Convert.o frams/util/rndutil.o common/virtfile/stringfile.o $(PRINTFLOAT_OBJS)
    3234
    3335GEOMETRY_OBJS=frams/model/geometry/meshbuilder.o frams/model/geometry/modelgeometryinfo.o frams/model/geometry/geometryutils.o
  • cpp/frams/config/sdk_build_config.h

    r732 r826  
    1414#endif
    1515
     16#define USE_PRINTFLOAT_DRAGON4
    1617#define NOCREATUREOBJECT
    1718#define SDK_WITHOUT_FRAMS
  • 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;
  • cpp/frams/util/sstring.cpp

    r793 r826  
    2323#include "extvalue.h"
    2424#include <assert.h>
     25#ifdef USE_PRINTFLOAT_DRAGON4
     26#include <PrintFloat/PrintFloat.h>
     27#endif
    2528
    2629#ifdef MULTITHREADED
     
    363366SString SString::valueOf(double d)
    364367{
    365         SString tmp = SString::sprintf("%.15g", d);
     368#ifdef USE_PRINTFLOAT_DRAGON4
     369        SString tmp;
     370        char* here=tmp.directWrite(30);
     371        tmp.endWrite(PrintFloat64(here,30,d,
     372                                  ((d<-1e17)||(d>1e17)||((d<1e-4)&&(d>-1e-4)&&(d!=0.0)))
     373                                  ? PrintFloatFormat_Scientific : PrintFloatFormat_Positional,
     374                                  -1));//http://www.ryanjuckett.com/programming/printing-floating-point-numbers/
     375#else
     376        SString tmp = SString::sprintf("%.17g", d); //https://stackoverflow.com/questions/16839658/printf-width-specifier-to-maintain-precision-of-floating-point-value
     377#endif
    366378        if ((!strchr(tmp.c_str(), '.')) && (!strchr(tmp.c_str(), 'e'))) tmp += ".0";
    367379        return tmp;
Note: See TracChangeset for help on using the changeset viewer.