log1pmx {DPQ} | R Documentation |
log(1+x) - x
Compute
log(1+x) - x
accurately also for small x, i.e., |x| << 1.
log1pmx(x, tol_logcf = 1e-14)
x |
numeric vector with values x > -1. |
tol_logcf |
a non-negative number indicating the tolerance
(maximal relative error) for the auxiliary |
In order to provide full accuracy, the computations happens differently in three regions for x,
m_l = -0.79149064
is the first cutpoint,
use log1pmx(x) := log1p(x) - x
,
use t((((2/9 * y + 2/7)y + 2/5)y + 2/3)y - x),
use t(2y logcf(y, 3, 2) - x),
where t := x/(2+x), and y := t^2.
Note that the formulas based on t are based on the (fast converging) formula
log(1+x) = 2(r + r^3/3 + r^5/5 + ...),
where r := x/(x+2), see the reference.
a numeric vector (with the same attributes as x
).
A translation of Morten Welinder's C code of Jan 2005, see R's bug issue PR#7307.
Abramowitz, M. and Stegun, I. A. (1972)
Handbook of Mathematical Functions. New York: Dover.
https://en.wikipedia.org/wiki/Abramowitz_and_Stegun provides
links to the full text which is in public domain.
Formula (4.1.29), p.68.
logcf
, the auxiliary function,
lgamma1p
which calls log1pmx
, log1p
l1x <- curve(log1pmx, -.9999, 7, n=1001) abline(h=0, v=-1:0, lty=3) l1xz <- curve(log1pmx, -.1, .1, n=1001); abline(h=0, v=0, lty=3) l1xz2 <- curve(log1pmx, -.01, .01, n=1001); abline(h=0, v=0, lty=3) l1xz3 <- curve(-log1pmx(x), -.002, .002, n=2001, log="y", yaxt="n") sfsmisc::eaxis(2); abline(v=0, lty=3)