root [0] TMath::Power(-8,0.3333)
Error: Symbol nan is not defined in current scope :0:
(Double_t)nan
root [1] TMath::Power(8,(1/3))
(Double_t)1.00000000000000000e+00
root [2] TMath::Power(-8,(1/3))
(Double_t)1.00000000000000000e+00

None of these answers are correct. Am I doing something completely stupid?

Thanks in advance.
Alan.

I have checked this on the following systems, and both have the same symptom:

MacOSX 10.4.7 PPC
8.7.0 Darwin Kernel Version 8.7.0: Fri May 26 15:20:53 PDT 2006; root:xnu-792.6.76.obj~1/RELEASE_PPC Power Macintosh powerpc
Root Version 5.11/06 1 June 2006
gcc version 4.1.0 20051124 (prerelease)

Thanks for the reply - the final two now make sense (and I was being stupid).

However, it doesn’t answer the first one, as the cube root of -8 is -2:

root [2] TMath::Power(-8.0,static_cast(1)/static_cast(3))
Error: Symbol nan is not defined in current scope :0:
(Double_t)nan
*** Interpreter error recovered ***

[quote]
root [2] TMath::Power(-8.0,static_cast(1)/static_cast(3))
Error: Symbol nan is not defined in current scope :0:
(Double_t)nan
*** Interpreter error recovered ***
Am I being stupid again?[/quote]

Casts will not help you 1.f / 3.f (or 1./3.) is a floating point number, which != mathematical 1/3. You need a LISP or something like this (it has a special type for ratio) . But in C++ you can simply take TMath::Power(8, 0.3333), the result will be near 2 and you know, it must be negative

[quote=“man pow”]The pow() function can return the following error:
EDOM The argument x is negative and y is not an integral value. This would result in a complex number.[/quote] I disagree with their definition of complex numbers, but we’ll have to live with that.

[quote=“man pow”]The pow() function can return the following error:
EDOM The argument x is negative and y is not an integral value. This would result in a complex number.[/quote] I disagree with their definition of complex numbers, but we’ll have to live with that.
[/quote]

When ‘x is negative and y is not an integral value’, you can always come up with complex roots (as well as possibly a real one as well).

In any case, if you want ‘cuberoot (-27.)’ to give you ‘-3’, you’ll want to keep track of the sign of the argument and appy it after