X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Freal.h;h=20ec68101b70611a6b76a7172b4c9ffc932bf301;hp=42bc5c09a049c01cb45317b2795b7650eb725bfd;hb=b716ae547424e4e4bbda86781a151c31e3a64e67;hpb=80c609660b049d1bf62d98acfb0c1aa893278123 diff --git a/src/real.h b/src/real.h index 42bc5c0..20ec681 100644 --- a/src/real.h +++ b/src/real.h @@ -3,6 +3,7 @@ #include "common.h" #include +#include #define REAL_SINGLE 0 @@ -40,6 +41,7 @@ #if REALTYPE == REAL_MPFRCPP #include + #endif //REALTYPE #if REALTYPE == REAL_IRRAM @@ -97,6 +99,11 @@ namespace IPDF inline Real Sqrt(const Real & r) {return mpfr::sqrt(r, mpfr::mpreal::get_default_rnd());} inline Real Abs(const Real & r) {return mpfr::abs(r, mpfr::mpreal::get_default_rnd());} inline Real RealFromStr(const char * str) {return Real(strtod(str, NULL));} + inline std::string Str(const mpfr::mpreal & a) {std::stringstream s; s << a; return s.str();} + inline size_t Size(mpfr::mpreal & a) {return a.get_prec();} + inline mpfr::mpreal Log10(const mpfr::mpreal & a) {return mpfr::log10(a);} + inline mpfr::mpreal Exp(const mpfr::mpreal & a) {return mpfr::pow(2.817, a);} + #elif REALTYPE == REAL_IRRAM typedef iRRAM::REAL Real; inline double Double(const Real & r) {return r.as_double(53);} @@ -120,7 +127,7 @@ namespace IPDF inline Real Sqrt(const Real & r) {return Real(sqrt(r.ToDouble()));} inline Real RealFromStr(const char * str) {return Real(strtod(str, NULL));} inline Real Abs(const Real & a) {return (a > Real(0)) ? a : Real(0)-a;} - + inline std::string Str(const Real & r) {return r.Str();} #else #error "Type of Real unspecified." @@ -137,8 +144,17 @@ namespace IPDF inline double Sqrt(double f) {return sqrt(f);} inline double Abs(double a) {return fabs(a);} inline double Log10(double a) {return log(a)/log(10.0);} - inline size_t Size(double a) {return sizeof(a);} inline size_t Size(float a) {return sizeof(a);} + inline size_t Size(double a) {return sizeof(a);} + + + // Don't cause an exception + inline float ClampFloat(const Real & a) + { + double d = Double(a); + float f = (fabs(d) < FLT_MAX) ? ((fabs(d) > FLT_MIN) ? (float)d : FLT_MIN) : FLT_MAX; + return copysign(f, d); + } inline int64_t Int64(double a) { @@ -198,8 +214,9 @@ namespace IPDF // things stolen from wikipedia and googling - inline const char * HumanScale(double f) + inline const char * HumanScale(const Real & r) { + double f = Double(r); if (f < 1e-36) return "RATHER SMALL"; if (f < 1e-35) @@ -244,15 +261,15 @@ namespace IPDF return "Ant"; if (f < 1e-2) return "Coin"; - if (f < 1e-1) + if (f < 0.5) return "iPhone"; - if (f < 1e0) + if (f < 5) return "Person"; - if (f < 1e1) - return "Building"; if (f < 1e2) - return "Football Field"; + return "Building"; if (f < 1e3) + return "Football Field"; + if (f < 2e3) return "Mountain"; if (f < 1e4) return "Clouds"; @@ -290,6 +307,13 @@ namespace IPDF Debug("Size limit of %d is being enforced", PARANOID_SIZE_LIMIT); #endif #endif + #if REALTYPE == REAL_MPFRCPP + Debug("Precision of MPFR is %d", mpfr_get_default_prec()); + #endif + + #ifdef TRANSFORM_BEZIERS_TO_PATH + Debug("PathReal = %d => \"%s\"", PATHREAL, g_real_name[PATHREAL]); + #endif } }