Repository navigation
Read an ISO 8601 duration's number as one decimal - #117810
Algunenano merged 6 commits into
Conversation
The fractional part was accumulated as `value += digit * scale` with `scale`
starting at 0.1 and multiplied by 0.1 each step. Neither 0.1 nor its powers is
representable in binary, so every term was rounded before it was added and the
errors compounded: `parseISO8601Duration('PT0.7S')` returned 0.7000000000000001,
`parseISO8601Duration('PT0.7S') = 0.7` was false, and 700 of the 1000 fractions
`PT0.<n>S` differed from the double the same decimal parses to. The integer loop
built the value the same way and lost exactness above 2^53.
Hand the numeric substring to `tryReadFloatTextPrecise` instead, which returns the
closest representable double to the input. Validation is unchanged: the substring
is still only digits and at most one point, so there is no exponent to read.
The tests only used fractions that happen to be representable - 0.5, 1.5, 5.5 -
which is why this was not caught. They now check a decimal that is not, and sweep
all 1000 of `PT0.<n>S` against `toFloat64` of the same decimal.
|
Workflow [PR], commit [dadf40d] Summary: ❌
AI ReviewSummaryThis PR replaces digit-by-digit accumulation in Final Verdict
LLVM Coverage ReportMeasured on commit dadf40d.
Changed lines: Changed C/C++ lines covered: 14/16 (87.50%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units17 translation units recompiled, 15 s compile time in total, 14 of them have a recent master baseline. |
|
I traced the new number path end to end and the fix is correct for the claimed shape: the scanner still enforces digits-plus-at-most-one-dot before the substring is built (leading One behavior change looks unintended, though. The vendored fast-float sets Related, minor: per-component overflow ( Since the function is new in this development cycle, both are bug-in-PR observations, not released regressions. |
Algunenano
left a comment
There was a problem hiding this comment.
LGTM, but since this wasn't part of any release it should not be tagged as BugFix, and instead we should simply use Not For Changelog
The comment claimed the integer part stays exact past 2^53, which no `Float64` can
do - `toFloat64('9007199254740993')` is already 9007199254740992. The assertion is
parity with `toFloat64` on the same decimal text, which is the contract the fix
gives; say that instead.
|
Thanks for tracing it that carefully - the first part matches what I intended, so it is good to have it confirmed independently. On the two behaviour notes though, I think they rest on /// result_out_of_range means overflow/underflow: fast_float has already set x to +-inf or +-0,
/// matching strtod semantics. Only a genuine parse failure is an error.
if (unlikely(res.ec != std::errc() && res.ec != std::errc::result_out_of_range))and the same condition on the slow path at
Which would mean the fix you suggest - treat I would rather be wrong about this than leave a hole, so if you traced a different path to |
|
@yariks5s could you take a look at this one when you get a chance? It is a defect in #116993 that you merged, not a new feature - the fractional part was accumulated as Merged master in 16e2d00, so the |
|
Thanks - you are right, and the PR body already said as much ("Introduced by #116993, so nothing released is affected") while the category said Bug Fix, which was inconsistent of me. Changed to Not for changelog and swapped the label to |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
|
For whoever picks this up: Algunenano's approval is on Green on the current head, branch is clean. |
|
@qoega thanks for queueing this. It was ejected by the pre-merge hook rather than by anything in the change: Every real job (Fast test, builds, style) was dropped rather than run. The branch was 2062 commits behind master, and while it still merged into public master with no conflicts, the sync mirror had gone stale. I have merged current master in — I have done the same for #117977 and #118005, which were from the same week and would have hit this on their way in. |
|
@navneet83 Please tone down the AI messages. You should own and handle your PRs and messages |
5bc0675
Closes: #117808
Related: #116993
Changelog category (leave one):
Documentation entry for user-facing changes
The fractional part was accumulated as
value += digit * scale, withscalestarting at0.1and multiplied by0.1at each step. Neither0.1nor any of its powers is representable in binary, so every term was rounded before it was added and the errors compounded:700 of the 1000 fractions
PT0.<n>Sdiffered from the double that the same decimal parses to. The integer loop had the same shape (value = value * 10 + digit) and lost exactness above 2^53.The numeric substring now goes to
tryReadFloatTextPrecise, which is documented as always returning the closest machine representable number to the input. Validation is unchanged - the substring still holds only digits and at most one decimal point, so there is no exponent for the reader to consume, and the existing rejections (P1.5,P1.D,PT1,5S, the overflow cases) keep working.Why the tests missed it. Every fraction they used -
PT1.5S,PT0.5H,P1DT12H30M5.5S- happens to be exactly representable, so the accumulated error was zero. The new cases check a decimal that is not representable and sweep all 1000 ofPT0.<n>SagainsttoFloat64of the same decimal, which is a property rather than a handful of examples.Introduced by #116993, so nothing released is affected.
Workflow [PR]
Sync PR [sync-upstream/pr/117810]