Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting warning from C math library's pow function

I have the following function in my code:

int numberOverflow(int bit_count, int num, int twos) {
    int min, max;
    if (twos) {
        min = (int) -pow(2, bit_count - 1);        \\ line 145
        max = (int) pow(2, bit_count - 1) - 1;
    } else {
        min = 0;
        max = (int) pow(2, bit_count) - 1;         \\ line 149
    }
    if (num > max && num < min) {
        printf("The number %d is too large for it's destination (%d-bit)\n", num, bit_count);
        return 1;
    } else {
        return 0;
    }
}

At compile time I get the following warning:

assemble.c: In function ‘numberOverflow’:
assemble.c:145: warning: incompatible implicit declaration of built-in function ‘pow’
assemble.c:149: warning: incompatible implicit declaration of built-in function ‘pow’

I'm at a loss for what is causing this... any ideas?

like image 711
Ian Burris Avatar asked Sep 20 '10 03:09

Ian Burris


People also ask

Why is pow function not working in C?

On some online compilers, the following error may occur. The above error occurs because we have added “math. h” header file, but haven't linked the program to the following math library. Link the program with the above library, so that the call to function pow() is resolved.

How do you fix undefined reference to POW in C?

a . You need to link your program with this library so that the calls to functions like pow() are resolved. This solved my issue.

What is Pow C?

C pow() The pow() function computes the power of a number. The pow() function takes two arguments (base value and power value) and, returns the power raised to the base number. For example, [Mathematics] xy = pow(x, y) [In programming] The pow() function is defined in math.

Which library contains the POW function?

C library function - pow() The C library function double pow(double x, double y) returns x raised to the power of y i.e. xy.


1 Answers

You need to include math.h

And why exactly do we get this warning?

like image 103
codaddict Avatar answered Oct 07 '22 23:10

codaddict