rfc:precise_float_value

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:precise_float_value [2016/06/05 19:02] – Update voting choice bukkarfc:precise_float_value [2016/07/09 12:05] – this RFC has already been implemented cmb
Line 3: Line 3:
   * Date: 2015-07-30   * Date: 2015-07-30
   * Author: Yasuo Ohgaki <yohgaki@ohgaki.net>, Jakub Zelenka <bukka@php.net>   * Author: Yasuo Ohgaki <yohgaki@ohgaki.net>, Jakub Zelenka <bukka@php.net>
-  * Status: Under Discussion+  * Status: Implemented (PHP 7.1)
   * First Published at: http://wiki.php.net/rfc/precise_float_value   * First Published at: http://wiki.php.net/rfc/precise_float_value
  
Line 10: Line 10:
 This RFC is based on the discussion about displaying float values in json_encode and proposes more precise float value handling overall. This RFC is based on the discussion about displaying float values in json_encode and proposes more precise float value handling overall.
  
-JSON is used to exchange data between systems. Although [[https://tools.ietf.org/html/rfc7159|JSON RFC "6 Numbers"]]  does not require specific implementation for float/int type, float value should be handled as precise as possible by default. +JSON is used to exchange data between systems. Although [[https://tools.ietf.org/html/rfc7159|JSON RFC "6 Numbers"]] does not require specific implementation for float/int type, float value should be handled as precise as possible by default.
  
-Currentlyjson_encode() uses EG(precision) which is set to 14. That means that 14 digits max are used for displaying (printing) the number. IEEE 754 double supports higher precision and serialize()/var_export() uses PG(serialize_precision)=17 to be more precise. Since json_encode() uses EG(precision), json_encode() removes lower digits of fraction parts and destroys original value even if PHP's float could hold more precise float value.+Currently json_encode() uses EG(precision) which is set to 14. That means that 14 digits at most are used for displaying (printing) the number. IEEE 754 double supports higher precision and serialize()/var_export() uses PG(serialize_precision) which set to 17 be default to be more precise. Since json_encode() uses EG(precision), json_encode() removes lower digits of fraction parts and destroys original value even if PHP's float could hold more precise float value.
  
 <code php> <code php>
Line 62: Line 62:
 ===== Proposal ===== ===== Proposal =====
  
-This RFC proposes to introduce EG(precision)=-1 and PG(serialize_precision)=-1 that uses zend_dtoa()'s mode 0 which uses better algorigthm for rounding float numbers (-1 is used to indicate 0 mode).+This RFC proposes to introduce a new setting EG(precision)=-1 and PG(serialize_precision)=-1 that uses zend_dtoa()'s mode 0 which uses better algorigthm for rounding float numbers (-1 is used to indicate 0 mode).
  
 The RFC also proposes changing ini for JSON precision to PG(serialize_precision). The RFC also proposes changing ini for JSON precision to PG(serialize_precision).
Line 178: Line 178:
  
  
-===== Proposed Voting Choices =====+===== Voting =====
  
-Requires a 2/3 majority+Requires a 2/3 majority for the first vote (mode 0 to become default for serialize precision) and 50%+1 majority for the second vote (changing default for json).
  
-There will be two votings+The both votes are straight Yes/No votes.
  
-  * whether to introduce mode 0 and use it as default for serialize_precision +<doodle title="Should mode 0 be introduced and set as default for PG(serialize_precision)" auth="bukka" voteType="single" closed="true"> 
-  should PG(serialize_precision) be used instead of EG(precision) in json_encode.+   Yes 
 +   * No 
 +</doodle> 
 + 
 +<doodle title="Should PG(serialize_precision) be used instead of EG(precision) in json_encode" auth="bukka" voteType="single" closed="true"> 
 +   * Yes 
 +   * No 
 +</doodle> 
 + 
 +The votes started on 2016-06-12 at 19:00 UTC and ended on 2016-06-19 at 19:00 UTC.
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
Line 193: Line 202:
   * https://github.com/php/php-src/pull/1455   * https://github.com/php/php-src/pull/1455
  
-Note that the PR is currently outdate but it will be updated if the RFC is accepted.+Note that the PR is currently outdated but it will be updated if the RFC is accepted.
  
 ===== Implementation ===== ===== Implementation =====
 +
 +Merged into php-src for PHP 7.1: https://github.com/php/php-src/commit/75b86a2
 +
 After the project is implemented, this section should contain  After the project is implemented, this section should contain 
-  - the version(s) it was merged to 
-  - a link to the git commit(s) 
   - a link to the PHP manual entry for the feature   - a link to the PHP manual entry for the feature
  
Line 208: Line 218:
  
 ===== Rejected Features ===== ===== Rejected Features =====
-Keep this updated with features that were discussed on the mail lists.+ 
 +None
  
rfc/precise_float_value.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1