Skip to content

Commit fab2796

Browse files
committed
improve formatting of null values, closes #48
1 parent f6bc663 commit fab2796

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# errors 0.4.2
22

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

56
# errors 0.4.1
67

R/print.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ format.errors = function(x,
4545

4646
e <- signif(.e(x), digits)
4747
nulle <- e == 0 & !is.na(e)
48-
xexp <- get_exponent(x)
48+
xexp <- ifelse(.v(x) == 0, get_exponent(e) + 1, get_exponent(x))
4949
value_digits <- ifelse(e, digits - get_exponent(e), digits)
5050
value <- ifelse(e, signif(.v(x), xexp + value_digits), .v(x))
5151
value <- ifelse(is.finite(value), value, .v(x))

tests/testthat/test-print.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ test_that("error formatting works properly", {
5757
expect_equal(format(x[3]), "NaN(NaN)")
5858
expect_equal(format(x[4]), "Inf(Inf)")
5959
expect_equal(format(x[5]), "-Inf(Inf)")
60+
61+
x <- set_errors(c(0e10, 1e12), 0.1e12)
62+
expect_equal(format(x), c("0.0(1)e12", "1.0(1)e12"))
63+
expect_equal(format(x, digits=2), c("0.00(10)e12", "1.00(10)e12"))
6064
})

0 commit comments

Comments
 (0)