Conclusion: better to check before using the feature that the number is less than zero. Even better use multiplication by -1 than this function.[*EDIT* by danbrown AT php DOT net: Merged users corrected code with previous post content.]

jeremys indicated one thing – there is no sgn function wich actually seems a bit strange for me. Of course it is as simple as possible, but it is usefull and it is a standard math function needed occasionally.

Well, I have solved this function in a bit different matter: