Pow (-1,1.2) is required to be 1

I am using math.h with GCC and GSL. I was wondering how to evaluate this?

I was hoping the pow function would recognize pow (-1,1,2) as ((-1) ^ 6) ^ (1/5). But this is not so.

Does anyone know a C ++ library that recognizes them? Perhaps someone has a decomposition procedure that they could share.

+3
source share
6 answers

It seems that you are looking pow(abs(x), y).


Explanation: you seem to think in terms of

x y = (x N ) (y / N)

If we choose N === 2, then you

(x 2 ) y / 2 = ((x 2 ) 1/2 ) y

But

(x 2) 1/2= | x |

| |

, x, .

+3

pow(-1, 1.2) . , , , . ,

pow(-1, 0.5) = ((-1)^2)^(1/4) = 1

, , .

, 1.2 6/5. 1.2

1.1999999999999999555910790149937383830547332763671875

, pow(-1, 1.2)?

+11

, , cpow(). <complex>, .

+9

, (cpow()), (abs()) .

>>> abs(cmath.exp(1.2*cmath.log(-1)))
1.0
>>> abs(cmath.exp(1.2*cmath.log(-293.2834)))
913.57662451612202
+1

pow(a,b) , exp(log(a)*b), log(a) a. log (a) a <= 0 . a integer b / b=1/(some_integer). b, b=1/(some_integer) , .

, pow(-a,b) -pow(a,b)? ​​, , .

duskwuff, "" log exp, "" ( ), ( cpow ). , pow() s.

, : , pow(a,b) , , , , ( - ), / .

, , pow(-1,.5). X , X^2==-1. , ? 2 : i -i. , pow(-1, 1/N) N , .

pow(a,b) , , . 1e-6 * max (abs (a), abs (b)) " " . " " pow(-1,0.5), 0 + 1i (0 , 1 ). , , .

In any reasonable implementation with one returns a result cpow(), cpow(-1,0.3333)probably will return something like -1+0.000001iand ignore the other two values with significant imaginary parts. Therefore, you can simply accept this real value and respond.

+1
source

Use std::complex. Without this, the roots of unity do not make much sense. With this, they make a lot of sense.

0
source

All Articles