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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: milahu89 at web dot de
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jun 18 18:01:31 2025 UTC