#include "common.h"
#include <cmath>
+#include <cfloat>
#define REAL_SINGLE 0
#if REALTYPE == REAL_MPFRCPP
#include <mpreal.h>
+
#endif //REALTYPE
#if REALTYPE == REAL_IRRAM
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);}
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)
{