# Thread: Math.pow

1. Registered User
Join Date
Nov 2013
Posts
44

## Math.pow

whay it gives me NAN
HTML Code:
`Math.pow(-.39,0.33);`
actually here var cube2 value is giving NAN

HTML Code:
```function solve_cube(){
var m=document.getElementById("gets");
var n=document.getElementById("divs");
n.style.display="none";
var a=prompt("put coeff of x^3");
var b=prompt("put coeff of x^2");
var c=prompt("put coeff of x");
var d=prompt("put value of d");
var front=(-b/(3*a));
var three=2*Math.pow(b,3)-(9*a*b*c)+27*(a*a)*d;
var last=Math.pow((b*b-3*a*c),3);
var under_root=(three*three)-(4*last);
var root=Math.sqrt(under_root);
var for_cube_root1=(1/2)*(three+root);
var for_cube_root2=(1/2)*(three-root);
alert(for_cube_root1);
var cube1=Math.pow(for_cube_root1,0.33);
var cube2=Math.pow(for_cube_root2,0.33);
cube1=(1/(3*a))*cube1;
cube2=(1/(3*a))*cube2;

var x1=front-cube1-cube2;

m.value="x1 = "+x1;

}```

2. 1. You have a negative base and powers can not be negative
2. you are missing the leading zero.

3. Registered User
Join Date
Nov 2013
Posts
44
how it can be solved.if i want result the calculation need to be done this way.its in the formula.actually i am making a calculator code.and it does the cubic eqn ax3+bx2+cx+d
roots calculation.

4. Registered User
Join Date
Nov 2013
Posts
44
i have done this
var cube2=-(Math.pow(-for_cube_root2,0.33));
but still feeling confused.is there any better way?

5. Using the Math.abs() method of the Math object to convert a negative number in to a positive value.

Code:
`var cube2 = Math.pow( Math.abs( for_cube_root2), 0.33 );`

#### Thread Information

##### Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•