rfc:change_the_edge_case_of_round
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:change_the_edge_case_of_round [2023/11/08 14:06] – saki | rfc:change_the_edge_case_of_round [2023/12/08 00:37] (current) – saki | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Change the edge case of round() ====== | ====== PHP RFC: Change the edge case of round() ====== | ||
- | * Version: 0.3.0 | + | * Version: 0.4.1 |
* Date: 2023-10-23 | * Date: 2023-10-23 | ||
* Author: Saki Takamachi, saki@sakiot.com | * Author: Saki Takamachi, saki@sakiot.com | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
Line 73: | Line 73: | ||
==== Reference: For other languages ==== | ==== Reference: For other languages ==== | ||
- | Ruby is similar | + | Similar |
- | Python rounds | + | Ruby: |
+ | < | ||
+ | p 0.285.round(2) | ||
+ | // 0.29 | ||
+ | |||
+ | p 0.28499999999999998.round(2) | ||
+ | // 0.29 | ||
+ | </ | ||
+ | |||
+ | Python: | ||
+ | < | ||
+ | // Python rounds | ||
+ | |||
+ | print(round(1.555, 2)) | ||
+ | // 1.55 | ||
+ | |||
+ | print(round(1.5549999999999999, 2)) | ||
+ | // 1.55 | ||
+ | </ | ||
+ | |||
+ | Ruby behaves | ||
+ | |||
+ | ==== Reference: Databases ==== | ||
+ | |||
+ | When it comes to databases, there are two types of values: exact values and approximate values. Verify using approximate values to align with PHP. Since even rounding may occur, I use 1.555, just like in Python. | ||
+ | |||
+ | MySQL: | ||
+ | < | ||
+ | mysql> SELECT 1555E-3 = 15549999999999999E-16; | ||
+ | +---------------------------------+ | ||
+ | | 1555E-3 = 15549999999999999E-16 | | ||
+ | +---------------------------------+ | ||
+ | | 1 | | ||
+ | +---------------------------------+ | ||
+ | |||
+ | mysql> SELECT ROUND(1555E-3, | ||
+ | +-------------------+ | ||
+ | | ROUND(1555E-3, | ||
+ | +-------------------+ | ||
+ | | 1.56 | | ||
+ | +-------------------+ | ||
+ | |||
+ | mysql> SELECT ROUND(15549999999999999E-16, | ||
+ | +---------------------------------+ | ||
+ | | ROUND(15549999999999999E-16, | ||
+ | +---------------------------------+ | ||
+ | | 1.56 | | ||
+ | +---------------------------------+ | ||
+ | </ | ||
+ | |||
+ | SQLite3: | ||
+ | < | ||
+ | sqlite> SELECT 1555E-3 = 15549999999999999E-16; | ||
+ | 1 | ||
+ | sqlite> SELECT ROUND(1555E-3, | ||
+ | 1.56 | ||
+ | sqlite> SELECT ROUND(15549999999999999E-16, | ||
+ | 1.56 | ||
+ | </ | ||
+ | |||
+ | Firebird: | ||
+ | < | ||
+ | SQL> SELECT 1555E-3 FROM RDB$DATABASE; | ||
+ | |||
+ | | ||
+ | ======================= | ||
+ | 1.554999999999999937828 | ||
+ | |||
+ | SQL> SELECT ROUND(1555E-3, | ||
+ | |||
+ | ROUND | ||
+ | ======================= | ||
+ | 1.560000000000000053291 | ||
+ | </ | ||
+ | |||
+ | SqlServer: | ||
+ | < | ||
+ | 1> SELECT 1555E-3; | ||
+ | 2> go | ||
+ | |||
+ | ------------------------ | ||
+ | 1.5549999999999999 | ||
+ | |||
+ | 1> SELECT ROUND(1555E-3, | ||
+ | 2> go | ||
+ | |||
+ | ------------------------ | ||
+ | 1.55 | ||
+ | </ | ||
+ | |||
+ | MySQL, SQLite, Firebird are similar to current PHP. SqlServer | ||
+ | |||
+ | PostgreSQL cannot round double precision values if we specify digits, so omit it. | ||
===== Proposal ===== | ===== Proposal ===== | ||
Line 83: | Line 175: | ||
// previous behavior | // previous behavior | ||
var_dump(round(0.285, | var_dump(round(0.285, | ||
+ | var_dump(round(0.28499999999999998, | ||
// new behavior | // new behavior | ||
var_dump(round(0.285, | var_dump(round(0.285, | ||
+ | var_dump(round(0.28499999999999998, | ||
</ | </ | ||
Line 120: | Line 214: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | We will probably | + | |
+ | As per the voting RFC a yes/ | ||
+ | Voting started on 2023-11-24 and will end on 2023-12-08 00:00 GMT. | ||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Implementation ===== | ===== Implementation ===== |
rfc/change_the_edge_case_of_round.1699452383.txt.gz · Last modified: 2023/11/08 14:06 by saki