Skip to content

Increase tolerance for compare() when long doubles aren't available #940

@richierocks

Description

@richierocks

CRAN recently started testing packages on machines where long double aren't available. This can cause broken tests that require many package developers to spend time scouring the internet for a solution.

There's a nice overview of the issues and solution here: https://blog.r-hub.io/2019/05/21/nold

It seems that many problems would disappear with a small change to testthat::compare().

Currently in the signature to testthat:::compare.numeric, tolerance defaults to .Machine$double.eps^0.5.

I think a better default is .Machine$double.eps ^ if(capabilities("long.double")) 0.5 else 0.25.

If silently increasing the tolerance worries you, it could be done with a message.

get_default_tolerance <-  function() {
  pwr <- if(capabilities("long.double")) {
    0.5
  } else {
    message("Long doubles are not available, so tolerance is increased.")
    0.25
  }
  .Machine$double.eps ^ pwr
}

Then the argument default would be tolerance = get_default_tolerance().

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