Bug #75192 [Ana->Nab]: Spaceship operator returns wrong value for GMP numbers
| From: | cmb@php.net | Date: | Tue, 12 Sep 2017 09:49:00 +0000 |
| Subject: | Bug #75192 [Ana->Nab]: Spaceship operator returns wrong value for GMP numbers | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211086@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75192&edit=1
ID: 75192
Updated by: cmb@php.net
Reported by: marcospassos dot com at gmail dot com
Summary: Spaceship operator returns wrong value for GMP
numbers
-Status: Analyzed
+Status: Not a bug
Type: Bug
Package: GNU MP related
Operating System: Mac
PHP Version: 7.1.9
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> Though personally I wish <=> wasn't so rigid to begin with.
It is not. Actually, the documentation states[1]:
> An integer less than, equal to, or greater than zero when $a is
> respectively less than, equal to, or greater than $b. Available
> as of PHP 7.
So this is not a bug.
One might desire a sign() function, so that the result of <=>,
strcmp() etc. could easily be used in a switch, but that would be
a separate feature request, and can be implemented in user-land,
of course.
[1] <http://php.net/manual/en/language.operators.comparison.php>
Previous Comments:
------------------------------------------------------------------------
[2017-09-12 05:19:16] requinix@php.net
gmp's <=> overload wraps gmp_cmp() so it should be a pretty simple fix to
gmp.c:gmp_compare to bound the return to -1/+1.
Though personally I wish <=> wasn't so rigid to begin with.
------------------------------------------------------------------------
[2017-09-12 01:38:42] marcospassos dot com at gmail dot com
In fact, the operator overloading works, but the result is not compatible with the operator
specification.
------------------------------------------------------------------------
[2017-09-12 01:34:56] marcospassos dot com at gmail dot com
Description:
------------
Operator overloading does not work for the spaceship operator.
Test script:
---------------
$result = gmp_init('1') <=> gmp_init('-1');
Expected result:
----------------
1
Actual result:
--------------
2
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75192&edit=1