Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Account for rounding errors when comparing float lengths
Adapted from [1] and [2]. More details on the underlying issue can also be found there. We neither need to deal with very large, nor with very small numbers in layout. So using an arbitrary epsilon should be perfectly fine (`PHP_FLOAT_EPSILON` is only available starting from PHP 7.2); it is selected so that it results in a precision of at least: * 7 decimal digits at around 1 * 4 decimal digits at around 1000 (around the size of common paper formats) * 2 decimal digits at around 100,000 (100,000pt ~ 35.28m) This should be more than enough for any reasonable number used. If anything, the epsilon value can easily be tuned later; just note that the tests would need change, as many of them demonstrate the effect of the (approximate) epsilon. I started using the new comparison functions in critical places I found, i.e. where a failure to detect equality could result in a meaningful difference in rendering, particularly the checks for fitting text and inline-block elements onto the current line, as the available width there may be the result of a shrink-to-fit width calculation. Open question: Maybe it would be more appropriate to treat all negative values as unequal to zero, regardless of the difference, so that we don't accidentally end up with (very small) negative width or height values in some places. [1] https://floating-point-gui.de/errors/comparison/ [2] https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ Fixes #2560
- Loading branch information
Showing
5 changed files
with
134 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters