This is an old revision of the document!

PHP RFC: Your Title Here


GMP arithmetic with normal operator is added by https://wiki.php.net/rfc/operator_overloading_gmp

GMP numbers work like normal PHP number(int/float) with normal PHP arithmetic operators now.

This RFC proposes GMP number compatible with PHP number(int/float).

Current GMP implementation does not support GMP float/rational numbers. For the sake of completeness, GMP float support is needed at least. There are functions to be modified to treat GMP number as normal PHP numbers.


Add GMP float support to GMP module

Add GMP float support to GMP module.

  • Add all GMP float API wrapper to module.
  • GMP float API wrapper supports PHP int/float and GMP int/float. Conversion is done automatically.
  • Default precision: 256 (?)

Add GMP float support to Zend OP

Add GMP float support to operators.

  • Arithmetic with GMP float and any number(PHP int/float, GMP int) is promoted to GMP float.

Add math function compatibility

Add math function compatibility.

  • Down grade GMP number (int/float) to PHP number (int/float) automatically.

Some other RFC may implement, full GMP number support in math functions, but this is out of this RFC scope.

Add variable function compatibility

Add variable function compatibility.

  • empty() - evaluated GMP int 0 and GMP float 0.0 as TRUE, otherwise FALSE.
  • is_scalar() - evaluated GMP number as TRUE.
  • (anything else?)

Backward Incompatible Changes

Proposed PHP Version(s)

PHP 5.6 or later

Impact to Existing Extensions

GMP module will have GMP float support.

php.ini Defaults

If there are any php.ini settings then list:

  • hardcoded default values
    • gmp_precision=256
  • php.ini-development values
    • gmp_precision=256
  • php.ini-production values
    • gmp_precision=256

Open Issues

  • Ways to implement GMP object evaluation in empty(), is_scalar()
    • Treat GMP object as special object
    • Implement scalar object
    • Implement autoboxing like feature
  • How GMP number should behave (Like PHP or Ruby?)
  • GMP float support API design

Future Scope

Math functions is better to support GMP float.

Proposed Voting Choices


Patches and Tests

I really appreciate if anyone could make patch for this RFC.


After the project is implemented, this section should contain

  1. the version(s) it was merged to
  2. a link to the git commit(s)
  3. a link to the PHP manual entry for the feature


Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/gmp_number.1388446838.txt.gz · Last modified: 2017/09/22 13:28 (external edit)