php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #35025 new function: sgn()
Submitted: 2005-10-30 17:10 UTC Modified: 2006-04-03 13:10 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: milahu89 at web dot de Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.0.5 OS: irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-10-30 17:10 UTC] milahu89 at web dot de
Description:
------------
not really a bug, but i'd like to suggest a new math-function sgn().
it would make comparison of integer values much easier (an nicer, of course ;)).
i've attached an example in the srccode part.

Reproduce code:
---------------
<?php
// comparison with if/else :
if($a < $b) print("a < b");
elseif($a == $b) print("a == b");
else print("a > b");

// comparison with sgn() :
function sgn($int) {
    if($int > 0) return 1;
    if($int < 0) return -1;
    return 0;
}
switch(sgn($a-$b)){
    case 1: print("a > b");
    case 0: print("a == b");
    case -1: print("a < b");
}
?>

Expected result:
----------------
depends ;)

Actual result:
--------------
depends ...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-03 13:10 UTC] tony2001@php.net
It's easy to implement with the code you've provided.
No need for yet another one rarely used core function.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 01:01:30 2024 UTC