From maechler@stat.math.ethz.ch  Fri Mar  1 20:23:55 2002
From: maechler@stat.math.ethz.ch (maechler@stat.math.ethz.ch)
Date: Fri, 1 Mar 2002 21:23:55 +0100 (MET)
Subject: [Rd] pexp.c (PR#1335)
Message-ID: <200203012023.VAA17931@pubhealth.ku.dk>

>>>>> "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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] pexp.c (PR#1335)
maechler@stat.math.ethz.ch