almightyegg Posted August 11, 2007 Share Posted August 11, 2007 I have a formula like ($variable^0.5)/4 but, at the moment it is echoing it out as $variable/4, does PHP not take ^ symbol as powers?? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 11, 2007 Share Posted August 11, 2007 No. Use www.php.net/pow Quote Link to comment Share on other sites More sharing options...
almightyegg Posted August 11, 2007 Author Share Posted August 11, 2007 That worked, but now I have found another problem, I need to use this formula with positives and negatives, but it works incorrectly with negatives and shows 'NAN' ?? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 11, 2007 Share Posted August 11, 2007 Worked fine for me <?php echo pow (4, 0.5); // --> 2 echo pow (4, -0.5); // --> 0.5 ?> If, on the other hand, you are trying to get pow(-4, 0.5) then it will fall over as you can't get the square root of a negative number (without going into the realm of complex numbers) Quote Link to comment Share on other sites More sharing options...
almightyegg Posted August 11, 2007 Author Share Posted August 11, 2007 well, it is a strange thing I want it to do, if the number is positive I want it to calculate out a negative number, which I have done, and if it is already negative, then I want it to calculate out a positive number.. So would it be easier to remove the - from it? Also can INT columns take negatives? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 11, 2007 Share Posted August 11, 2007 Also can INT columns take negatives? As long as it isn't defined as UNSIGNED Quote Link to comment Share on other sites More sharing options...
almightyegg Posted August 11, 2007 Author Share Posted August 11, 2007 Ah k, so to remove the - should I use a replace and replace it with nothing? Quote Link to comment Share on other sites More sharing options...
corbin Posted August 11, 2007 Share Posted August 11, 2007 well, it is a strange thing I want it to do, if the number is positive I want it to calculate out a negative number, which I have done, and if it is already negative, then I want it to calculate out a positive number.. So would it be easier to remove the - from it? Also can INT columns take negatives? You could just do something like: if($num < 0) { //negative } elseif($num > 0) { //positive } else { //0 } Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 11, 2007 Share Posted August 11, 2007 http://ca.php.net/manual/en/function.abs.php - absolute value Quote Link to comment Share on other sites More sharing options...
almightyegg Posted August 11, 2007 Author Share Posted August 11, 2007 well, it is a strange thing I want it to do, if the number is positive I want it to calculate out a negative number, which I have done, and if it is already negative, then I want it to calculate out a positive number.. So would it be easier to remove the - from it? Also can INT columns take negatives? You could just do something like: if($num < 0) { //negative } elseif($num > 0) { //positive } else { //0 } That's what I've been doing, but the problem wasn't that, it was passing the negative number, as it can't compute it... http://ca.php.net/manual/en/function.abs.php - absolute value That didn't work... hmm, could I just remove the hyphen - somehow? Quote Link to comment Share on other sites More sharing options...
Barand Posted August 11, 2007 Share Posted August 11, 2007 As AndyB said $x = -5; $x = abs($x); echo $x; Quote Link to comment Share on other sites More sharing options...
almightyegg Posted August 11, 2007 Author Share Posted August 11, 2007 I went back to my code, I realised when I tried abs() before I'd put it in completely the wrong place :S oops thanks for the help guys Quote Link to comment 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.