Skip to content

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

Open

Description

@alusiani

Hi,

the CRAN present version of the package formats with digits="pdg"

1.234 +- 0.0950  ->  1.2 +- 0.1 (expected: 1.23 +- 0.10)

In short, the case of last three digits 950-999 should format to 10 with 2 digits, and formats 1 digit instead.

I have produced here a working version: https://github.com/alusiani-forked/errors, starting from the current https://github.com/cran/errors .

If acceptable, I can propose a pull request. There are some modifications to print.R and utils.R. I have added an additional argument, that could facilitate a future extension to asking the PDG number of digits plus an extra offset. This argument does nothing now.

Cheers,

Alberto

Activity

  1. Enchufa2 commented on Mar 8, 2026

    @Enchufa2
    Member

    PR welcome. Adding @davidchall to the conversation because he added this functionality. It would be nice to have new tests that fail under the current version and succeed with the fix.

  2. davidchall commented on Mar 8, 2026

    @davidchall
    Contributor

    Hi @Enchufa2 - Yes, @alusiani is correct and this was an oversight on my part in #59.

    Below I've highlighted the relevant piece of the PDG guidelines:

    5.3. Rounding : While the results shown in the Particle Listings are usually exactly those published by the experiments, the numbers that appear in the Summary Tables (means, averages and limits) are subject to a set of rounding rules.

    The basic rule states that if the three highest order digits of the error lie between 100 and 354, we round to two significant digits. If they lie between 355 and 949, we round to one significant digit. Finally, if they lie between 950 and 999, we round up to 1000 and keep two significant digits. In all cases, the central value is given with a precision that matches that of the error. So, for example, the result (coming from an average) 0.827 ± 0.119 would appear as 0.83 ± 0.12, while 0.827 ± 0.367 would turn into 0.8 ± 0.4.

    The following test case should be updated such that the final expected value is c("0.8", "1.0"):

    x <- set_errors(rep(0.827, 3), c(0.119, 0.367, 0.962))
    expect_equal(format(x, notation="plus-minus", digits="pdg"), sapply(list(
    c("0.83", "0.12"), c("0.8", "0.4"), c("1", "1")),
    paste, collapse=paste("", .pm, "")))

  3. alusiani commented on Mar 17, 2026

    @alusiani
    ContributorAuthor

    I want to mention that I do plan to submit a PR. I could not find the time so far because I am too busy with work affairs. But I will submit when I find the time.

  4. Enchufa2 commented on Mar 17, 2026

    @Enchufa2
    Member

    Perfect, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions