chrisbcats Posted May 24, 2006 Share Posted May 24, 2006 How do I caculate exponents (powers) in php?Here is my formula:$netValue = ($margin_benefit * (1 + $weightAverage)^(($improvment/365) - $margin_benefit));I need:[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]($margin_benefit * (1 + $weightAverage) [!--colorc--][/span][!--/colorc--]to be raised to the [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--](($improvment/365) - $margin_benefit))[!--colorc--][/span][!--/colorc--]power Quote Link to comment https://forums.phpfreaks.com/topic/10363-caculate-exponents/ Share on other sites More sharing options...
micah1701 Posted May 24, 2006 Share Posted May 24, 2006 I beleive the pow() function should do it.[a href=\"http://us2.php.net/manual/en/function.pow.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.pow.php[/a] Quote Link to comment https://forums.phpfreaks.com/topic/10363-caculate-exponents/#findComment-38627 Share on other sites More sharing options...
chrisbcats Posted May 24, 2006 Author Share Posted May 24, 2006 wow! that was easy. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/10363-caculate-exponents/#findComment-38677 Share on other sites More sharing options...
chrisbcats Posted May 25, 2006 Author Share Posted May 25, 2006 k, that works. Here is my new problem:pow ( base, exp );PHP cannot handle negative bases. I have a negative exponent. The function returns 0.$netValue = pow(4140000,-3599999.9);How can I comupte a negative exponent? Quote Link to comment https://forums.phpfreaks.com/topic/10363-caculate-exponents/#findComment-38938 Share on other sites More sharing options...
AndyB Posted May 25, 2006 Share Posted May 25, 2006 Calculate for the positive exponent and then take the reciprocal.x^-y = 1/x^y Quote Link to comment https://forums.phpfreaks.com/topic/10363-caculate-exponents/#findComment-38941 Share on other sites More sharing options...
chrisbcats Posted May 25, 2006 Author Share Posted May 25, 2006 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/10363-caculate-exponents/#findComment-38947 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.