rfc:gmp-floating-point

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
rfc:gmp-floating-point [2014/01/04 07:00] – created pollitarfc:gmp-floating-point [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
  
 ====== PHP RFC: GMP Floating Point Support ====== ====== PHP RFC: GMP Floating Point Support ======
-  * Version: 1.0+  * Version: 1.1
   * Date: 2014-01-04   * Date: 2014-01-04
   * Author: Sara Golemon, pollita@php.net   * Author: Sara Golemon, pollita@php.net
Line 11: Line 11:
 @yohgaki suggested adding support for libgmp's arbitrary precision floating point numbers to the PHP extension, and I offered to implement it, so here's my proposal. @yohgaki suggested adding support for libgmp's arbitrary precision floating point numbers to the PHP extension, and I offered to implement it, so here's my proposal.
  
-===== Proposal =====+===== Proposal #1 =====
  
 Extend `gmp_object` struct to the following: Extend `gmp_object` struct to the following:
Line 33: Line 33:
  
 Add gmp_floatval(), gmp_isint(), gmp_isfloat(), and similar introspection functions. Add gmp_floatval(), gmp_isint(), gmp_isfloat(), and similar introspection functions.
 +
 +===== Proposal #2 =====
 +
 +Rather than overload the GMP class for integer/float representations, organize Integer and Floating-Point GMP objects into a class heirarchy as so:
 +
 +  abstract class GMPNumber {}
 +  class GMPInt extends GMPNumber {}
 +  class GMPFloat extends GMPNumber {}
 +
 +The same open questions exist for this approach (i.e. should int/int yield float?)
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
  
-gmp_init_float() is being added to specifically avoid breakage in code currently supplying numbers which may (or may not) have decimal separators in them.  Not that overloading gmp_init() to detect floating point numbers would also present a challenge as GMP parses numbers based on system locale which may use '.', ',', or other separators.  Having a unique initializer avoids that problem.+gmp_init_float() is being added to specifically avoid breakage in code currently supplying numbers which may (or may not) have decimal separators in them.  Note that overloading gmp_init() to detect floating point numbers would also present a challenge as GMP parses numbers based on system locale which may use '.', ',', or other separators.  Having a unique initializer avoids that problem.
  
 Actor functions and operator overloads should remain unaffected (with one exception, below) as code producing gmp_objects now will continue to do so, with the single (invisible) addition of the type byte. Actor functions and operator overloads should remain unaffected (with one exception, below) as code producing gmp_objects now will continue to do so, with the single (invisible) addition of the type byte.
Line 54: Line 64:
 Add INI setting: Add INI setting:
 gmp.default_precision=(libgmp-initial-default-precision) gmp.default_precision=(libgmp-initial-default-precision)
 +
 +===== History =====
 +
 +  * Version 1.0: 2014-01-04 Initial Draft
 +  * Version 1.1: 2014-01-05 Added proposal #2
  
 ===== Implementation ===== ===== Implementation =====
rfc/gmp-floating-point.1388818823.txt.gz · Last modified: 2017/09/22 13:28 (external edit)