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?? Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/ Share on other sites More sharing options...
Barand Posted August 11, 2007 Share Posted August 11, 2007 No. Use www.php.net/pow Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/#findComment-321180 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' ?? Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/#findComment-321206 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) Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/#findComment-321216 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? Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/#findComment-321225 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 Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/#findComment-321228 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? Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/#findComment-321240 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 } Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/#findComment-321241 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 Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/#findComment-321250 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? Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/#findComment-321263 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; Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/#findComment-321278 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 Link to comment https://forums.phpfreaks.com/topic/64423-solved-mmm/#findComment-321287 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.