Skip to content

Fix PDG rounding for 950-999 uncertainty values - #70

Merged
Enchufa2 merged 4 commits into
r-quantities:masterfrom
davidchall:davidchall-fix-digits-pdf-last-error
Nov 8, 2026
Merged

Enchufa2 merged 4 commits into
r-quantities:masterfrom
davidchall:davidchall-fix-digits-pdf-last-error

Conversation

@davidchall

Copy link
Copy Markdown
Contributor

Why

Particle Data Group rounding treats uncertainties whose leading three digits fall in the 950-999 range as a special case: they round up to 1000 and keep two significant digits. The previous logic treated those values like the 355-949 case, which produced a one-digit uncertainty instead of the expected two-digit result.

What changed

  • corrected the PDG digit selection so 950-999 uncertainties keep two significant digits
  • added the 1000-up rounding step before formatting those values
  • added a regression test covering the reported 0.827 +/- 0.962 case

Fixes #65

davidchall and others added 2 commits November 6, 2026 15:50
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Round 950-999 uncertainties up to the next power of ten explicitly,
  since round() rounded e.g. 0.95 down to 0.9
- Share the highest-order-digit extraction via pdg_hod() and round once
- Add tests for the boundary, other magnitudes and both notations
- Add NEWS entry under a new devel header

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Enchufa2

Enchufa2 commented Nov 7, 2026

Copy link
Copy Markdown
Member

Thanks @davidchall for spinning this! I reviewed it with our French Friend and found some issues, they were simple enough, so I committed them directly:

  • Fix the 950 boundary: values that land exactly on the 950 boundary (e.g. 0.95, or 0.9495 once it rounds to three digits) were being rounded down by round(), giving 1.00 ± 0.90. Uncertainties in the 950–999 range are now set straight to the next power of ten, so they print as 1.0 ± 1.0.
  • Single rounding step: the uncertainty is now rounded once, at the top of format.errors(), instead of being rounded and then partly overwritten.
  • Shared helper: the three-highest-order-digit extraction now lives in one helper, pdg_hod(). digits_pdg() uses its result, and pdg_round_to_1000() is gone.
  • Less repeated work: the uncertainties are extracted once and the digit extraction runs once per call.
  • Tests: added cases for the 950 boundary (0.95, 0.9495), larger and smaller uncertainties (96.2, 9.62e-6), and the parenthesis, plus-minus and scientific notations.

@davidchall @alusiani Could you please try this?

Enchufa2 and others added 2 commits November 7, 2026 11:14
Cover the 100/354/355/949/950/999 edges, 0.9996 rolling over to the
next power of ten, the rounded (not truncated) three highest digits,
zero/negative values and zero/NA/Inf errors with digits="pdg".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alusiani

alusiani commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

...

@davidchall @alusiani Could you please try this?

I tested the patched errors package, I found it 100% compliant with PDG prescriptions. You can go ahead, this is an improvement of the released code.

@Enchufa2
Enchufa2 merged commit 410aa99 into r-quantities:master Nov 8, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix for digits="pdf" last error digits 950-999 case

3 participants