# Exp[x] answers 1 for small x [duplicate]

I'm getting the same answer "1" for Exp[x] with x less than "1.1*10^-16", and I really need to calculate much smaller numbers (in order of 10^-40).

I tried using SetPrecision[Exp[x],1000].

Obviously I'm doing something wrong. #_-

Edit:

Maybe this screenshot could make it easier to understand what I'm talking about.

## marked as duplicate by Szabolcs, Yves Klett, MarcoB, Feyre, EdmundNov 27 '16 at 15:20

• Try N[Exp[11/10000000000000000000000], 4000]. In other words, use rational numbers and not numbers with decimal points when you need lots of precision. – JimB Nov 26 '16 at 20:16
• By default only 6 digits are displayed, see Preferences -> Appearance -> Numbers -> Displayed precision. Edit the output cell to see all. In your last examples first you compute something ridiculously close to 1 using machine precision (15 digits), and only after you get the result you increase the precision ... – Szabolcs Nov 26 '16 at 20:22
• Thank you guys for your quick replies. I've tried them. @JimBaldwin I have other calculations that results to "x" which is not rational. Like divisions and stuff. I think I'm going to lose accuracy If I Rationalize my "x" right? – Pedram Ashofteh Ardakani Nov 26 '16 at 20:28
• Most languages' standard libraries provide an expm1 function for this purpose, which returns $\exp(x)-1$ to high precision even when $\exp(x)$ would return exactly $1$. Mathematica unfortunately doesn't, but if that's your goal, you could implement something similar along the lines of log1p. – Rahul Nov 27 '16 at 3:19

You're setting the precision too late.

Exp[1.200*^-40]


and

Exp[SetPrecision[1*^-40, 200]]


yield

On the other hand,

SetPrecision[Exp[1.*^-40], 200]


yields

because Exp[1.*^-40] evaluates to 1. (exactly, in machine precision), before it is passed to SetPrecision.

• Woah Thanks! You made my day! – Pedram Ashofteh Ardakani Nov 26 '16 at 20:30
• @PedramAshofteArdakani You're welcome. – Michael E2 Nov 26 '16 at 20:31
• Hi again! I noticed something strange here, Exp[SetPrecision [1.1^-40, 200]] , Exp[(1.1200)^-40] and Exp[(SetPrecision[1.1, 200])^-40] Hold different answers, aren't these supposed to be identical? – Pedram Ashofteh Ardakani Dec 2 '16 at 18:06
• @PedramAshofteArdakani I don't think they supposed to be identical. 1.1^40 is first computed in 16-digit machine precision and will have significant differences when compared to the other 200-digit precision results. For the difference in the other two, examine 1.1200 // FullForm and SetPrecision[1.1, 200] // FullForm. Here the difference arises because 1.1200 is parsed to have 200-digit precision, whereas with SetPrecision, the 1.1 is first evaluated at 16-digit machine precision, then converted to 200-digit precision. – Michael E2 Dec 2 '16 at 23:19