How do you do exponentiation in C?

前端 未结 7 1512
执笔经年
执笔经年 2020-12-05 06:31

I tried \"x = y ** e\", but that didn\'t work.

7条回答
  •  囚心锁ツ
    2020-12-05 07:01

    To add to what Evan said: C does not have a built-in operator for exponentiation, because it is not a primitive operation for most CPUs. Thus, it's implemented as a library function.

    Also, for computing the function e^x, you can use the exp(double), expf(float), and expl(long double) functions.

    Note that you do not want to use the ^ operator, which is the bitwise exclusive OR operator.

提交回复
热议问题