C's pow function refuses to work with variable exponent

后端 未结 5 1475
遥遥无期
遥遥无期 2021-01-17 20:59

Let\'s say I have the following code snippet:

int i; double value;
for(i = 0; i < CONSTANT; i++) {
  value = (double)pow(2, i);
}

Trying

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-17 21:27

    The code for pow is part of the math library. You need to link in that library (in addition to the C library that is linked in by default).

    To do that, with gcc, specify -lm on the compiler invocation

    gcc ... -lm
    

提交回复
热议问题