# Why can't pow(10,1/3) display correctly?

on
Why can't pow(10,1/3) display correctly?
How to improve the part of pow function?
Comment
Watch Question

Do more with

EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
The problem with pow(10,1/3) is that 1/3 is integer division, and thus returns 0 to the function pow.  10^0 is one.  If you put pow(10,1/3.0), pow will return the correct results.

HTH,
Odog

Commented:
i agree with ODOG1999......by the way you should realise that the second parameter in pow() is 1/3....the compiler will evaluate the result of 1/3 as an interger instead of floating point......thus 1/3 = 0 for int type data....you also can put it this way "pow(10,(float)(1/3))" to cast the expression of 1/3 as floating no....

from
ksboyz

Commented:
Just a slight clarification on the comment from ksboyz, it looks like a typo where the parenthesis are in the wrong place.

pow(10, (float)(1/3)) will not correctly cast 1/3 to the float number 0.3333....  Instead it will cast the integer result of 1/3 (which is 0) to a float which will be 0.0.

The correct cast is pow(10, ((float)1)/3);

Either the 1 or the 3 must be a floating point type before the divison.

Commented:
Or even better...
Simply write: pow(10,1.0/3)
:)

Commented:
or the pow(10,1/3/0) that I put in the first response :-)

Commented:
Sorry, :) Didn't see that.
Top Expert 2006

Commented:
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:
PAQed with A grade to  odog1999

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.