Req #70896 [Asn->Csd]: Invalid result with decimals
| From: | pollita@php.net | Date: | Wed, 27 Jul 2016 05:05:13 +0000 |
| Subject: | Req #70896 [Asn->Csd]: Invalid result with decimals | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202630@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70896&edit=1
ID: 70896
Updated by: pollita@php.net
Reported by: xavier at pandawan-technology dot com
Summary: Invalid result with decimals
-Status: Assigned
+Status: Closed
Type: Feature/Change Request
Package: GNU MP related
Operating System: Any
PHP Version: Irrelevant
Assigned To: pollita
Block user comment: N
Private report: N
New Comment:
The fix for this bug has been committed.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2016-07-27 04:20:46] pollita@php.net
I disagree. Factorial calculation *is* only valid for non-negative integers, the reason Google is
able to give you an answer is, quite simply, because it's cheating.
The Gamma Function https://en.wikipedia.org/wiki/Gamma_function
when provided with 1-shifted non-negative integers happens to produce the same results as the
Factorial Function, however while the Gamma Function provides results for non-integer input, the
Factorial Function does not.
libGMP side-steps this problem by only accepting integer inputs. PHP has a bug in that it
doesn't complain about receiving non-integer inputs, simply truncating them instead.
Moreover, since PHP's implementation of the GMP extension doesn't support floating point
numbers, the only way this function could *appear* to work would be to first add support for foating
point GMP values (no small task when you factor in the complications of which numeric type should
and shouldn't be converted), THEN implement the Gamma Function ourselves.
The correct fix for this, IMO, is to raise a warning on receiving invalid input.
------------------------------------------------------------------------
[2015-11-12 00:19:24] xavier at pandawan-technology dot com
That would be great yeah
------------------------------------------------------------------------
[2015-11-12 00:05:17] requinix@php.net
So what you're saying is you want gmp to extend supporting factorials of real numbers, even
though factorial is traditionally only defined for integers?
------------------------------------------------------------------------
[2015-11-11 22:56:29] xavier at pandawan-technology dot com
Description:
------------
---
From manual page: http://www.php.net/function.gmp-fact
---
The value returned is not correct when providing decimal input for any PHP version the function
exists in
Test script:
---------------
See https://3v4l.org/fhsSZ
Expected result:
----------------
~496.6 For full result, see https://www.google.com/#q=5.8!
Actual result:
--------------
120 (correct value for input = 5)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70896&edit=1