dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: Math.pow

Hybrid View

  1. #1
    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. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,587
    1. You have a negative base and powers can not be negative
    2. you are missing the leading zero.
    If your post falls off the page, bump it. ...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    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?

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

  5. #5
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,587
    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 );
    If your post falls off the page, bump it. ...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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



Recent Articles