www.webdeveloper.com
Results 1 to 5 of 5

Thread: Math.pow

  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,204
    1. You have a negative base and powers can not be negative
    2. you are missing the leading zero.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    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. #4
    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. #5
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,204
    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 );
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

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