Link to home
Start Free TrialLog in
Avatar of cylam1000
cylam1000

asked on

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

Why can't pow(10,1/3) display correctly?
How to improve the part of pow function?
ASKER CERTIFIED SOLUTION
Avatar of odog1999
odog1999

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ksboyz
ksboyz

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

Or even better...
Simply write: pow(10,1.0/3)
:)
or the pow(10,1/3/0) that I put in the first response :-)
Sorry, :) Didn't see that.
Avatar of sunnycoder
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
https://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