Add log2 to @EVAL

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#3
FWIW, this works quite well, comparing perfectly vs. Mathematica with the likes of "log2.exe 81e-101 2000" and "log2.exe 81e-101 2000".
Code:
#include <windows.h>
#include <stdio.h>
#include "..\m_apm.h"

// Syntax: LOG2 x d(ecimal precision)
INT main ( INT argc, LPSTR *argv )
{
   if ( argc != 3 ) return 0;
   INT dp = atoi(argv[2]); // decimal places
   MAPM m_x(argv[1]);
   MAPM m_Two(2);
   MAPM m_log2ofx = (m_x.log(dp+3) / m_Two.log(dp+3)).round(dp+2);
   CHAR *szResult = (CHAR*) malloc(m_log2ofx.significant_digits() + dp + 3);
   m_log2ofx.toFixPtString(szResult, dp);
   printf("%s\n", szResult);
   free(szResult);
   return 0;
}