Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log2 not found in my math.h?

I'm using a fairly new install of Visual C++ 2008 Express.

I'm trying to compile a program that uses the log2 function, which was found by including using Eclipse on a Mac, but this Windows computer can't find the function (error C3861: 'log2': identifier not found).

The way I understood it, include directories are specific to the IDE, right? math.h is not present in my Microsoft SDKs\Windows\v6.0A\Include\ directory, but I did find a math.h in this directory: Microsoft Visual Studio 9.0\VC\include. There is also a cmath in that directory...

Where is log2?

like image 633
Tony R Avatar asked Apr 16 '09 20:04

Tony R


People also ask

Is there a log2 function in C?

The log2 function in C computes the base-2 logarithm of x . A domain error occurs if the argument is less than zero. A pole error may occur if the argument is zero.

What is the log2 function?

The log2() function returns the base-2 logarithm of a number. If the number is 0, the log2() function will return -Infinity. If the number is a negative value, the log2() function will return NaN.


1 Answers

From here:

Prototype: double log2(double anumber);
Header File: math.h (C) or cmath (C++)

Alternatively emulate it like here

#include <math.h>   ...   // Calculates log2 of number.   double Log2( double n )   {       // log(n)/log(2) is log2.       return log( n ) / log( 2 );   }   

Unfortunately Microsoft does not provide it.

like image 106
lothar Avatar answered Sep 23 '22 18:09

lothar