diff --git a/src/real.cpp b/src/real.cpp index 16b9914b..e143abf3 100644 --- a/src/real.cpp +++ b/src/real.cpp @@ -590,6 +590,23 @@ real cbrt(real const &x) return ret; } +real pow(real const &x, real const &y) +{ + if (!y) + return real::R_1; + if (!x) + return real::R_0; + if (x > real::R_0) + return exp(y * log(x)); + else /* x < 0 */ + { + if (y == round(y)) + return -exp(y * log(-x)); + /* FIXME: negative nth root */ + return real::R_0; + } +} + real fabs(real const &x) { real ret = x; @@ -1012,6 +1029,14 @@ real atan(real const &x) return ret; } +void real::hexprint() const +{ + printf("%08x", m_signexp); + for (int i = 0; i < BIGITS; i++) + printf(" %08x", m_mantissa[i]); + printf("\n"); +} + void real::print(int ndigits) const { real x = *this; diff --git a/src/real.h b/src/real.h index baf9206f..e4e3b3db 100644 --- a/src/real.h +++ b/src/real.h @@ -85,7 +85,7 @@ public: friend real re(real const &x); friend real sqrt(real const &x); friend real cbrt(real const &x); - /* FIXME: pow */ + friend real pow(real const &x, real const &y); /* Rounding, absolute value, remainder etc. */ friend real ceil(real const &x); @@ -95,6 +95,7 @@ public: friend real round(real const &x); friend real fmod(real const &x, real const &y); + void hexprint() const; void print(int ndigits = 150) const; static real const R_0;