# [R] Greater than 1 or less than 1?

Ray Brownrigg ray at mcs.vuw.ac.nz
Mon Jun 21 01:24:56 CEST 2004

```> Date: Sun, 20 Jun 2004 18:32:46 -0400
> From: "Zhen Chen" <zchen at cceb.upenn.edu>
>
> I have problem evaluating the expression h = exp(x)/(exp(exp(x))-1) for
> large negative x. This expression is actually the probability
> that y = 1 when y is a Poisson random variable truncated at 0, hence
> must satisfy 0 <= h <= 1. However, when
> x < -18, I may get an h value that is  larger than 1 while the true
> value should be a quantity that is smaller than but very close to 1.
> For example when x = -19, h = 1.00000000031174. I tried to use
> different form of h and none of
> them give me an h value that is less than or equal to 1. I also tried
> to find patterns, but discovered none: for some x < -18, h is below 1;
> for others
> h is greater than 1. Is there any trick that enables me to obtain
> theoretically correct results from this expression?
>
exp(x)/(exp(exp(x)) - 1) is less than 1 for me for x = -18 with R-1.9.0
on a Solaris 9 system, a NetBSD 2.0C system and a Windows XP system.

You could try exp(x)/expm1(exp(x)), but if the longer expression doesn't
work, then this may not either, though it does give slightly different
results on my systems.

E.g.:
> x = -19
> exp(x)/(exp(exp(x)) - 1) - 1
 -2.047911e-09
> exp(x)/(expm1(exp(x))) - 1
 -2.801398e-09

log(1 + x) and exp(x) - 1 are often treated specially in math libraries
for when x << 0.

Ray Brownrigg

```