X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Freal.h;h=13395fb75cac4457db0db17777c4c981ae8668d5;hp=42bc5c09a049c01cb45317b2795b7650eb725bfd;hb=f28146cf72fc68c8d3690814b1f89d47b8c4e7b9;hpb=5ef972c655ad9d17ac01e208c3d7bc57a4c10c7c diff --git a/src/real.h b/src/real.h index 42bc5c0..13395fb 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,10 @@ 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);} + #elif REALTYPE == REAL_IRRAM typedef iRRAM::REAL Real; inline double Double(const Real & r) {return r.as_double(53);} @@ -137,8 +143,16 @@ 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(double d) + { + 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) {