obtaining real roots of negative numbers in a long expression [duplicate]

I have a complicated symbolic expression which contains many terms like $(a/(a-2))^{1/m}$, where $a/(a-2)$ could be positive or negative after replacement.

I only need the real root after replacement, but Power[] function in Mathematica most of the time gives me a complex number instead. I found something that almost suits my need here (the realPower function by Peter Breitfeld), but I have a hard time get it working in the way I want.

For example:

((a/(-2 + a))^(1/3) /. {x_^y_ :> realPower[x, y]}) /. {a -> 0.5}

still gives me a complex number. (it seems that realPower only work with numerical values) What should I do to get only the real root after replacement?

marked as duplicate by Artes, Sjoerd C. de Vries, István Zachar, ssch, m_goldbergSep 26 '13 at 0:43

• If you read another answers to the question you linked to in your post you wouldn't have asked this one. – Artes Sep 25 '13 at 21:25