rfc:integer-rounding
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:integer-rounding [2024/02/25 17:05] – added force_float to example mabe | rfc:integer-rounding [2024/03/17 12:22] – open voting mabe | ||
---|---|---|---|
Line 13: | Line 13: | ||
Except '' | Except '' | ||
- | As a result of '' | + | As a result of '' |
In most cases this is sufficient but in cases of handling integer values above 2^53 you start to end up with unexpected results due to floating point arithmetic and precision loss. | In most cases this is sufficient but in cases of handling integer values above 2^53 you start to end up with unexpected results due to floating point arithmetic and precision loss. | ||
- | '' | + | '' |
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes to perform rounding on given int and return | + | This RFC proposes to perform rounding on given int and return |
In case of integer under-/ | In case of integer under-/ | ||
For '' | For '' | ||
+ | ---- | ||
+ | Rounding a given float will perform rounding on floating point number directly and return float as it's done currently. | ||
+ | There will be no implicit cast to int because floats (double) can represent a much wider range of numbers than int (32 or 64 bit). | ||
+ | Floating point numbers on the other hand gets imprecise on representing numbers > 2^53 but passing a float to be rounded such imprecision must be known in first place already. | ||
+ | ---- | ||
An additional argument will be introduced '' | An additional argument will be introduced '' | ||
In PHP 8.next this will default to '' | In PHP 8.next this will default to '' | ||
- | In PHP 9.0 the default will change to '' | + | In PHP 9.0 the default will change to '' |
Line 43: | Line 48: | ||
// rounding integers with force_float=false will process and return int if possible | // rounding integers with force_float=false will process and return int if possible | ||
- | // else with force_float=true it will process on int but cast the result to float to keep previous behavior | ||
ceil(int, force_float=false): | ceil(int, force_float=false): | ||
ceil(int, force_float=true): | ceil(int, force_float=true): | ||
Line 51: | Line 55: | ||
round(int, precision: < 0, force_float=false): | round(int, precision: < 0, force_float=false): | ||
round(int, force_float=true): | round(int, force_float=true): | ||
- | |||
</ | </ | ||
Line 70: | Line 73: | ||
var_dump(round(987654321098765432, | var_dump(round(987654321098765432, | ||
var_dump(round(987654321098765432, | var_dump(round(987654321098765432, | ||
+ | var_dump(round(10000000000000055296)); | ||
var_dump(takeFloat(round(987654321098765432, | var_dump(takeFloat(round(987654321098765432, | ||
var_dump(returnFloat(round(987654321098765432, | var_dump(returnFloat(round(987654321098765432, | ||
Line 79: | Line 83: | ||
var_dump(round(987654321098765432, | var_dump(round(987654321098765432, | ||
var_dump(round(987654321098765432, | var_dump(round(987654321098765432, | ||
+ | var_dump(round(10000000000000055296, | ||
var_dump(takeFloat(round(987654321098765432, | var_dump(takeFloat(round(987654321098765432, | ||
var_dump(returnFloat(round(987654321098765432, | var_dump(returnFloat(round(987654321098765432, | ||
Line 88: | Line 93: | ||
var_dump(round(987654321098765432, | var_dump(round(987654321098765432, | ||
var_dump(round(987654321098765432, | var_dump(round(987654321098765432, | ||
+ | var_dump(round(10000000000000055296, | ||
var_dump(takeFloat(round(987654321098765432, | var_dump(takeFloat(round(987654321098765432, | ||
var_dump(returnFloat(round(987654321098765432, | var_dump(returnFloat(round(987654321098765432, | ||
Line 98: | Line 104: | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
float(9.8765432109877E+17) | float(9.8765432109877E+17) | ||
+ | float(1.0000000000000055E+19) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
Line 110: | Line 117: | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
float(9.8765432109877E+17) | float(9.8765432109877E+17) | ||
+ | float(1.0000000000000055E+19) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
Line 117: | Line 125: | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
float(9.8765432109877E+17) | float(9.8765432109877E+17) | ||
+ | float(1.0000000000000055E+19) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
Line 124: | Line 133: | ||
int(987654321098765000) | int(987654321098765000) | ||
float(9.8765432109877E+17) | float(9.8765432109877E+17) | ||
+ | float(1.0000000000000055E+19) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
Line 134: | Line 144: | ||
int(987654321098765000) | int(987654321098765000) | ||
float(9.8765432109877E+17) | float(9.8765432109877E+17) | ||
+ | float(1.0000000000000055E+19) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
Line 141: | Line 152: | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
float(9.8765432109877E+17) | float(9.8765432109877E+17) | ||
+ | float(1.0000000000000055E+19) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
Line 148: | Line 160: | ||
int(987654321098765000) | int(987654321098765000) | ||
float(9.8765432109877E+17) | float(9.8765432109877E+17) | ||
+ | float(1.0000000000000055E+19) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
float(9.87654321098766E+17) | float(9.87654321098766E+17) | ||
Line 189: | Line 202: | ||
- | ===== Proposed Voting Choices ===== | + | ===== Proposed Voting Choices ===== |
- | One primary | + | As per the voting RFC a yes/ |
+ | Voting started | ||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== |
rfc/integer-rounding.txt · Last modified: 2024/04/02 07:07 by mabe