On Wed, 12 Aug 2020, Alecos Papadopoulos wrote:
Now, consider series "Z" which has both positive /and/
negative values. We
want to compute
W = Z^(1/3)
Given a recent new feature in gretl, the sign function sgn(), I guess we can
avoid the obvious conditional if-else statement, and compute W by writing
W = sgn(Z) * (abs(Z)^(1/3))
that covers also the case of Z taking an exact zero value.
Is this the proper/efficient way?
My second reply. No, this is not proper!
<gretl>
? Z = -2
Generated scalar Z = -2
? W = sgn(Z) * (abs(Z)^(1.0/4))
Generated scalar W = -1.18921
? eval W^4
2
</gretl>
<octave>
octave:1> Z = -2
Z = -2
octave:2> W = Z^(1.0/4)
W = 0.84090 + 0.84090i
octave:3> W^4
ans = -2.0000e+00 + 1.2561e-15i
<octave>
There's a digital approximation involved in the octave answer, via
complex numbers, but it's basically right, while the answer
according to your proposal is flat wrong.
Allin