Skip to content

Commit a9fcda6

Browse files
author
maechler
committed
prettyNum(*, zero.print = {>=1-char}, replace.zero) bug fix
git-svn-id: https://svn.r-project.org/R/trunk@88238 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent a6d841f commit a9fcda6

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

doc/NEWS.Rd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
%% including tkrplot, loon and tcltk2
117117
}
118118
}
119-
119+
120120
\subsection{BUG FIXES}{
121121
\itemize{
122122
\item Java detection in \code{javareconf} could not detect
@@ -142,6 +142,11 @@
142142

143143
\item \code{signif(1.**e308, digits)} no longer truncates unnecessarily
144144
(but still to prevent overflow to \code{Inf}), fixing \PR{18889}.
145+
146+
\code{pbeta(x, a,b, ..)} for very large \code{a,b} no longer returns
147+
\code{NaN} but the correct values (0 or 1, or their logs for \code{log.p = TRUE}).
148+
This improves Mathlib's C level \code{bratio()} and hence also
149+
\code{pnbinom()}, etc..
145150
}
146151
}
147152
}

src/library/base/R/format.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/base/R/format.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2024 The R Core Team
4+
# Copyright (C) 1995-2025 The R Core Team
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -73,7 +73,7 @@ format.default <-
7373
decimal.mark = decimal.mark, input.d.mark = decimal.mark,
7474
zero.print = zero.print, drop0trailing = drop0trailing,
7575
is.cmplx = is.complex(x),
76-
preserve.width = if (trim) "individual" else "common"),
76+
preserve.width = if (trim) "individual" else "common", ...),
7777
## all others (for now):
7878
stop(gettextf("Found no format() method for class \"%s\"",
7979
class(x)), domain = NA))
@@ -338,7 +338,7 @@ prettyNum <-
338338
big.mark=big.mark, big.interval=big.interval,
339339
small.mark=small.mark, small.interval=small.interval,
340340
decimal.mark=decimal.mark, zero.print=zero.print,
341-
drop0trailing=drop0trailing, ...)
341+
drop0trailing=drop0trailing, replace.zero=replace.zero, ...)
342342
}
343343
## be fast in trivial case, when all options have their default, or "match"
344344
nMark <- big.mark == "" && small.mark == "" && (notChar || decimal.mark == input.d.mark)

tests/reg-tests-1e.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,18 @@ stopifnot(all.equal(1.1e308, signif(1.06e308, 2)),
19561956
all.equal(1.01e308, signif(1.0055e308, 3)))
19571957

19581958

1959+
## prettyNum(.., zero.print = <2-or-more-char>, replace.zero=TRUE) --
1960+
zp <- "--"; num <- -1:2
1961+
assertWarnV(
1962+
p1 <- prettyNum(num, zero.print = zp) )
1963+
p2 <- prettyNum(num, zero.print = zp, replace.zero=TRUE) # was Error (converted from warning)
1964+
stopifnot(identical(p1[2], substr(zp,1,1)),
1965+
identical(p2[2], zp),
1966+
identical(p1[num != 0], p2[num != 0]),
1967+
identical(p2, local({ p <- as.character(num); p[p == 0] <- zp; p })))
1968+
## p2 gave warning too, and was the same as p1, erronously in R <= 4.5.0
1969+
1970+
19591971

19601972
## keep at end
19611973
rbind(last = proc.time() - .pt,

0 commit comments

Comments
 (0)