Browse Source

core: implement pow() for real numbers; for now special cases such as

negative zero or negative nth roots are not handled.
legacy
Sam Hocevar sam 13 years ago
parent
commit
1280301f27
2 changed files with 27 additions and 1 deletions
  1. +25
    -0
      src/real.cpp
  2. +2
    -1
      src/real.h

+ 25
- 0
src/real.cpp View File

@@ -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;


+ 2
- 1
src/real.h View File

@@ -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;


Loading…
Cancel
Save