C's pow function refuses to work with variable exponent

后端 未结 5 1478
遥遥无期
遥遥无期 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:26

    You need to link with -lm to actually include the math library.

    It worked for a hardcoded value because the compiler optimized the pow call away.

提交回复
热议问题