Skip to content

Commit

Permalink
improve formatting of null values, closes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
Enchufa2 committed Jul 29, 2024
1 parent f6bc663 commit fab2796
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# errors 0.4.2

- Add support for PDG rounding rules (@davidchall #59 addressing #45).
- Improve formatting of null values (#48).

# errors 0.4.1

Expand Down
2 changes: 1 addition & 1 deletion R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ format.errors = function(x,

e <- signif(.e(x), digits)
nulle <- e == 0 & !is.na(e)
xexp <- get_exponent(x)
xexp <- ifelse(.v(x) == 0, get_exponent(e) + 1, get_exponent(x))
value_digits <- ifelse(e, digits - get_exponent(e), digits)
value <- ifelse(e, signif(.v(x), xexp + value_digits), .v(x))
value <- ifelse(is.finite(value), value, .v(x))
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-print.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ test_that("error formatting works properly", {
expect_equal(format(x[3]), "NaN(NaN)")
expect_equal(format(x[4]), "Inf(Inf)")
expect_equal(format(x[5]), "-Inf(Inf)")

x <- set_errors(c(0e10, 1e12), 0.1e12)
expect_equal(format(x), c("0.0(1)e12", "1.0(1)e12"))
expect_equal(format(x, digits=2), c("0.00(10)e12", "1.00(10)e12"))
})

0 comments on commit fab2796

Please sign in to comment.