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

cylam1000
cylam1000 used Ask the Experts™
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
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.

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

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 :-)
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Sunny
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial