X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Freal.h;h=5d4e1333ee14bf0204696c614c5a53119fc4c235;hp=9ea302dbc8ef83f7a8d4fce6d0aad55aeaa8a9c0;hb=6ce000e7212d9f5db6e5998c41df15bcad2022c8;hpb=77137590512d969da2d54d9ba53d76836a290c6a;ds=sidebyside diff --git a/src/real.h b/src/real.h index 9ea302d..5d4e133 100644 --- a/src/real.h +++ b/src/real.h @@ -46,18 +46,23 @@ namespace IPDF #if REALTYPE == REAL_SINGLE typedef float Real; + inline Real RealFromStr(const char * str) {return strtof(str, NULL);} #elif REALTYPE == REAL_DOUBLE typedef double Real; + inline Real RealFromStr(const char * str) {return strtod(str, NULL);} #elif REALTYPE == REAL_LONG_DOUBLE typedef long double Real; + inline Real RealFromStr(const char * str) {return strtold(str, NULL);} #elif REALTYPE == REAL_VFPU typedef VFPU::VFloat Real; inline float Float(const Real & r) {return r.m_value;} inline double Double(const Real & r) {return r.m_value;} + inline Real RealFromStr(const char * str) {return Real(strtod(str, NULL));} #elif REALTYPE == REAL_RATIONAL typedef Rational Real; inline float Float(const Real & r) {return (float)r.ToDouble();} inline double Double(const Real & r) {return r.ToDouble();} + inline Real RealFromStr(const char * str) {return Real(strtod(str, NULL));} #elif REALTYPE == REAL_RATIONAL_ARBINT #define ARBINT Gmpint // Set to Gmpint or Arbint here @@ -73,12 +78,14 @@ namespace IPDF inline int64_t Int64(const Real & r) {return r.toLong();} 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));} #elif REALTYPE == REAL_IRRAM typedef iRRAM::REAL Real; inline double Double(const Real & r) {return r.as_double(53);} inline float Float(const Real & r) {return r.as_double(53);} inline int64_t Int64(const Real & r) {return (int64_t)r.as_double(53);} inline Real Sqrt(const Real & r) {return iRRAM::sqrt(r);} + inline Real RealFromStr(const char * str) {return Real(strtod(str, NULL));} #else #error "Type of Real unspecified." #endif //REALTYPE @@ -137,6 +144,7 @@ namespace IPDF }; + inline Real RealFromStr(const std::string & str) {return RealFromStr(str.c_str());}