rfc:integer-rounding

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:integer-rounding [2024/03/10 21:00] – why float input will not be casted to int maberfc:integer-rounding [2024/03/18 15:13] – Fix grammar in a couple places theodorejb
Line 3: Line 3:
   * Date: 2023-09-26   * Date: 2023-09-26
   * Author: Marc Bennewitz, php@mabe.berlin   * Author: Marc Bennewitz, php@mabe.berlin
-  * Status: Under Discussion+  * Status: In voting phase
   * First Published at: https://wiki.php.net/RFC/integer-rounding   * First Published at: https://wiki.php.net/RFC/integer-rounding
  
Line 23: Line 23:
  
 This RFC proposes to perform rounding on given int and return a rounded int value if possible by default. This RFC proposes to perform rounding on given int and return a rounded int value if possible by default.
-In case of integer under-/overflow the value will be casted to a float (double) and rounded based on the floating point number as it's done currently.+In case of integer under-/overflow the value will be cast to a float (double) and rounded based on the floating point number as it's done currently.
  
 For ''ceil'', ''floor'' and ''round'' with ''precision >= 0'' this means a given int gets returned as is. For ''ceil'', ''floor'' and ''round'' with ''precision >= 0'' this means a given int gets returned as is.
Line 34: Line 34:
 An additional argument will be introduced ''bool force_float''. An additional argument will be introduced ''bool force_float''.
 In PHP 8.next this will default to ''force_float=true'' to keep current behavior but the new behavior can already be used by passing ''force_float=false''. In PHP 8.next this will default to ''force_float=true'' to keep current behavior but the new behavior can already be used by passing ''force_float=false''.
-In PHP 9.0 the default will change to ''force_float=true'' to get the new behavior by default but the previous behavior can be forced with ''force_float=true''.+In PHP 9.0 the default will change to ''force_float=false'' to get the new behavior by default but the previous behavior can be forced with ''force_float=true''.
  
  
Line 61: Line 61:
 The ''int''-type is compatible to ''float'', returning an int instead of a float will still be a number accepted for type-hints of ''int'', ''float'', ''int|float'' or ''mixed'' with strict_types enabled. The ''int''-type is compatible to ''float'', returning an int instead of a float will still be a number accepted for type-hints of ''int'', ''float'', ''int|float'' or ''mixed'' with strict_types enabled.
  
-As a result PHP will behave more precise on rounding integer values.+As a result PHP will behave more precisely on rounding integer values.
  
  
Line 196: Line 196:
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
-Rounding floating point numbers will not be effected in any way.+Rounding floating point numbers will not be affected in any way.
  
 ===== Future Scope ===== ===== Future Scope =====
-After PHP 9 it can be considered to deprecate and remove the `force_floatargument again but due to very long future this is not part of this RFC.+After PHP 9 it can be considered to deprecate and remove the ''force_float'' argument again but due to very long future this is not part of this RFC.
  
  
-===== Proposed Voting Choices ===== +===== Proposed Voting Choices =====  
-One primary vote (requires 2/3 majority): Round on int and return int+As per the voting RFC a yes/no vote with a 2/3 majority is needed for this proposal to be accepted. 
 +Voting started on 2024-03-17 and will end on 2024-04-02 00:00 GMT. 
 +<doodle title="Rounding Integers as int" auth="Marc Bennewitz" voteType="single" closed="false" closeon="2024-04-02T00:00:00Z"> 
 +   * Yes 
 +   * No 
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
rfc/integer-rounding.txt · Last modified: 2024/04/02 07:07 by mabe