1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Add log2 to @EVAL

Discussion in 'Suggestions' started by vefatica, Aug 11, 2017.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    log2(x) = log(x)/log(2) = log10(x)/log10(2)

    (if it's not available on its own)
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    SQRT() would be more convenient that ()**(.5)
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,971
    Likes Received:
    30
    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;
    }
    
     

Share This Page