# Math.pow

• 12-15-2013, 03:01 PM
alzami
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;                 }```
• 12-15-2013, 03:25 PM
\\.\
1. You have a negative base and powers can not be negative
2. you are missing the leading zero.
• 12-15-2013, 03:39 PM
alzami
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.
• 12-15-2013, 03:45 PM
alzami
i have done this
var cube2=-(Math.pow(-for_cube_root2,0.33));
but still feeling confused.is there any better way?
• 12-16-2013, 05:16 PM
\\.\
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 );`

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.10446 seconds
• Memory Usage 2,349KB
• Queries Executed 11 (?)
Template Usage (21):
• (1)bbcode_code_printable
• (2)bbcode_html_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates