#19621 [Opn->Csd]: Math needs a "sign()" function
| From: | andrey@php.net | Date: | Thu, 03 Oct 2002 07:32:28 +0000 |
| Subject: | #19621 [Opn->Csd]: Math needs a "sign()" function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-21353@lists.php.net to get a copy of this message | ||
ID: 19621
Updated by: andrey@php.net
Reported By: bill@softky.com
-Status: Open
+Status: Closed
Bug Type: Feature/Change Request
Operating System: Mandrake linux
PHP Version: 4.2.0
New Comment:
Quick search showed that there is no well know scripting language that
has such function. C++/C# has this but they are not scripting
languages.
The following code does the same. Also we have to think about
BC(backward compatibility) with older scripts.
function sign($x){
return (int)((abs($x)-$x)? -1:$x>0);
}
Thank you for you suggestion.
Previous Comments:
------------------------------------------------------------------------
[2002-09-26 13:52:07] bill@softky.com
The wonderful math-function list is missing a very important and simple
function: sign(). The is the comlpementof abs(), and together with
abs() allows you to separate the magnitude and sign of a number, e.g.
for graphing purposes (it's hard to graph a negative number of pixels,
and displaying money as "$-99" looks dumb).
It's a one-line function, so I've already written my own, but it really
ought to be built-in.
Thanks!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=19621&edit=1