Mercurial > hg > octave-nkf
diff liboctave/lo-mappers.cc @ 7740:39930366b709
implement builtin log2
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 30 Apr 2008 03:30:34 -0400 |
parents | 446dec9d1de5 |
children | 82be108cc558 |
line wrap: on
line diff
--- a/liboctave/lo-mappers.cc +++ b/liboctave/lo-mappers.cc @@ -139,13 +139,25 @@ #if defined (M_LN2) static double ln2 = M_LN2; #else - static double ln2 = log2 (2); + static double ln2 = log (2); #endif return log (x) / ln2; #endif } +Complex +xlog2 (const Complex& x) +{ +#if defined (M_LN2) + static double ln2 = M_LN2; +#else + static double ln2 = log (2); +#endif + + return std::log (x) / ln2; +} + double xexp2 (double x) { @@ -155,13 +167,27 @@ #if defined (M_LN2) static double ln2 = M_LN2; #else - static double ln2 = log2 (2); + static double ln2 = log (2); #endif return exp (x * ln2); #endif } +double +xlog2 (double x, int& exp) +{ + return frexp (x, &exp); +} + +Complex +xlog2 (const Complex& x, int& exp) +{ + double ax = std::abs (x); + double lax = xlog2 (ax, exp); + return (exp == 0) ? x : (x / ax) * lax; +} + // double -> bool mappers. bool