[Rd] pexp.c (PR#1335)
maechler@stat.math.ethz.ch
maechler@stat.math.ethz.ch
Fri, 1 Mar 2002 21:23:55 +0100 (MET)
>>>>> "Morten" == Morten Welinder <terra@diku.dk> writes:
Morten> If you want an expm1, this will do just fine, given
Morten> the availability of log1p. It compares well with
Morten> Solaris' expm1. (And, luckily, is much better than
Morten> just exp(x)-1...)
Morten> Morten
looks very reasonable; this might make it
(no promises yet).
Martin
Morten> double
Morten> myexpm1 (double x)
Morten> {
Morten> double y;
Morten> if (fabs (x) > 1e-6)
Morten> {
Morten> y = exp (x) - 1;
Morten> if (y > 10000)
Morten> return y;
Morten> }
Morten> else
Morten> y = (x / 2 + 1) * x; /* Taylor expansion */
Morten> /* Newton step. */
Morten> y -= (1 + y) * (log1p (y) - x);
Morten> return y;
Morten> }
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._