# Conflicting output provided by N[…]

I am trying to evaluate an expression :

(-((I (k2 - k1) (-1 + E^(2 I (k2 - k1) \[Pi])))/(-1 + (k2 -
k1)^2))) /. {k1 -> 2, k2 -> 7}


This gives output as 0. exactly. Then I tried this :

N[ (-((I (k2 - k1) (-1 + E^(2 I (k2 - k1) \[Pi])))/(-1 + (k2 -
k1)^2)))] /. {k1 -> 2, k2 -> 7}


This gives output as -2.55135*10^-16 + 0. I. Then I read up on the documentation of N[expr,n] and find that it can evaluate expr to n precision and try that.

N[ (-((I (k2 - k1) (-1 + E^(2 I (k2 - k1) \[Pi])))/(-1 + (k2 -
k1)^2))), 2] /. {k1 -> 2, k2 -> 7}


This gives output as 0.*10^-1 + 0.*10^-2 I. Now, I try this for different values of precision n and conclude that the output is zero upto the accuracy provided by precision.

But why does the usage of N[..] without any precision give me non zero result? It is of the order of 10^-16 so I thought that maybe MachinePrecision is set to 16 but no, trying N[...,16] results in exactly zero again.

Can someone please shed light on this so that I can trust the output given by N[] ?

• It's roundoff error. Either use Chop[] on a machine precision evaluation (Chop[N[expr]]) or use arbitrary precision exclusively (N[expr, prec]). – J. M.'s ennui Apr 29 '20 at 23:42
• @J.M.'stechnicaldifficulties So, in short, we should never use N[ ] without specifying precision even though Mathematica doesn't show any errors? – Nitin Apr 30 '20 at 16:51
• "Never" is too strong a word. By default, if the second argument of N[] is unspecified, it is set to MachinePrecision. – J. M.'s ennui May 2 '20 at 11:31
• Got it. Thanks :) – Nitin May 2 '20 at 14:11