note 58653 added to function.abs
| From: | rdk at osu1 dot php dot net | Date: | Thu, 10 Nov 2005 19:04:44 +0000 |
| Subject: | note 58653 added to function.abs | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-98403@lists.php.net to get a copy of this message | ||
concordia, you seem to be overcomplicating matters. If you want to do the reverse of the abs
function, the only code required is:
<?php
function n_abs($num) {
return ($num > 0) ? $num * -1 : $num;
}
n_abs(2); //-2
n_abs(-2); //-2
?>
If you want to switch the sign bit of a number, as your example seems to indicate...
turn_neg (2); // -2
turn_neg (-2); // 2
...you just need to do $num *= -1;
Your function also doesn't seem to work. Switching "if (is_neg ($num))" to "if
(!is_neg ($num))" would make it function as indicated by your comments (i.e. toggle the sign
bit), but it would still be overly complicated.
----
Manual Page -- http://www.php.net/manual/en/function.abs.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58653
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58653&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58653&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58653&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58653&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58653&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58653&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58653&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58653&report=yes
Search -- http://master.php.net/manage/user-notes.php