Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a real number $x$ (for concreteness, say $10^4<x<10^6$) and would like to find $e^x-\lfloor e^x\rfloor$ to reasonable precision (10-20 decimal places). What is the most efficient method?

Computing $e^x$ directly in an arbitrary-precision library works but this requires a lot of storage space (and hence time) to store digits that I just throw away. Is there a better approach?

Edit: If it would help I have $x=y+n$ where $y$ is fixed throughout all my calculations (an easily-computed real constant) and $n\in\mathbb{Z}.$ I'd like to do the calculation for a million values of $n$, give or take.

share|cite|improve this question
I'd guess you mean $\exp(x)-\lfloor \exp(x) \rfloor$? – DoomMuffins Jan 20 '13 at 19:54
@DoomMuffins: Oops, yes. – Charles Jan 20 '13 at 20:16
If $x\approx 10^4$ and you want to know $\exp x-\lfloor\exp x\rfloor$ to $10$ decimal places, then you'll have to know $x$ to over $4000$ decimal places. – Rahul Jan 20 '13 at 20:16
@RahulNarain: I do. – Charles Jan 20 '13 at 20:17
If the 4000th decimal digit of $x$ is significant, it would seem implausible that you could manage the calculation without 4000 digits of precision. – Hurkyl Jan 20 '13 at 20:26

It entirely depends on why this is important and how many values of $x$ are in question. All numerical methods are context dependent.

The standard example is much easier than your task. Take a polynomial in one variable. Write it in the most efficient method, Horner's. Then evaluate it at real numbers, far enough away that fixed length precision gives, essentially, gibberish.

In contrast, if the polynomial has integer coefficients, one may rewrite it as a finite Taylor series around a chosen integer point $n.$ If $|x-n| < 1,$ or better $|x-n| \leq \frac{1}{2}$ by rounding, we now get quite wonderful precision for the polynomial.

The bad news is that the strictly analogous procedure is to save an impossible number of values of $\log m$ for integers $e^{10^4} < m < e^{10^6}.$

So it still comes down to context.

share|cite|improve this answer
How many values of x: so far I've done about 60,000 with the slow "full precision plus guard digits" method. I'd like to be able to do ten million, if possible. – Charles Jan 20 '13 at 21:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.