You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Limit IntegerParseStrategy's fallback Double path to lossless integer range (#667)
* Some tests about IntegerParseStrategy's big int behavior w.r.t. Double.
IntegerParseStrategy currently tries to parse a Double when it fails to parse an Int64, which results in some odd behavior for magnitudes greater than 2^53. The oddities stem the from fact that the parseAsDouble(_:) method rounds its input String to the nearest Double. This commit adds some tests that fail when this happens.
* Updated: NumberParseStrategyTests/testNumericBoundsParsing().
I added some UInt8 and Int64 checks and some UInt64 test w.r.t. exact Double values.
* Do not round to the nearest Double when parsing integers greater than Int64.
This change rejects values greater than ±2^53 in IntegerParseStrategy's Double fallback path. This limit is the upper bound of Double's lossless integer range. The parseAsDouble(_:) method rounds greater magnitudes to the nearest Double. Ideally, the parser should not have to fall back on Double but that is out-of-scope of this contribution.
* Disabled UInt64 parsing tests for values in (Int64.max, UInt64.max].
See previous commits. The currently supported integer parsing range is [Int64.min, Int64.max].
* Corrects the lossless range in IntegerParseStrategy's fallback Double path.
A value of ±(2^53) may not be exact since ±(2^53+1) is not a Double and becomes ±(2^53) when rounded towards zero.
* Reenabled some IntegerParseStrategy tests in accordance with review comments.
The test suite now checks the new behavior rather than awaiting the desired behavior via code comments.
0 commit comments