Edit report at http://bugs.php.net/bug.php?id=19621&edit=1
ID: 19621 Comment by: patrick at ibuildings dot nl Reported by: bill at softky dot com Summary: Math needs a "sign()" function Status: Closed Type: Feature/Change Request Package: Feature/Change Request Operating System: Mandrake linux PHP Version: 4.2.0 Block user comment: N Private report: N New Comment: I also searched for a sign() function and ended up here. But I disagree with Andrey's arguments not to include it into PHP. Since when is it a policy to *not* include a function, simply because it does not exist in a number of other languages? Doesn't PHP have its own 'vision'? Secondly, a new function should not break BC. As Bill stated, it would complement the abs() function and make the Math list a more complete list, even though it's a simple function. It seems a better idea to me to add "sign()" then let's say "goto". Previous Comments: ------------------------------------------------------------------------ [2002-10-03 02:32:28] and...@php.net 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. ------------------------------------------------------------------------ [2002-09-26 13:52:07] bill at softky dot 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/bug.php?id=19621&edit=1