# Calculate the machine epsilon in Matlab

How can I calculate the machine epsilon for two numbers then calculate the theoretical limit for machine epsilon in Matlab ?

• Could you perhaps define what you mean by "theoretical limit for machine epsilon" here? A limit is defined with respect to a variable tending to some (possibly infinite) value; what is tending where, here? – Patrick Sanan Sep 12 '14 at 10:24

So, machine epsilon is an upper bound on the relative error due to roundoff. You can calculate this quantity using the eps function:

 eps
2.2204e-16


If you want to find the distance between a floating point number x and the next nearest floating point number, you would call eps(x) instead.

• Right I get that but say I have the number 124 and 120 if I did eps (124) and esp(120) how would I calculate the theoretical limit for machine eps? – Rain Sep 7 '14 at 20:35
• I don't understand what you're saying when you talk about "the theoretical limit for machine epsilon". That maximum relative error is eps, which is the limit of eps(x)/x as abs(x) approaches infinity; it's also eps(1). – Geoff Oxberry Sep 7 '14 at 20:44
• Do you have any ideas what the theoretical limit for machine epsilon could mean? Because that is what my hw questions ask to find and I have no idea how to do that. – Rain Sep 8 '14 at 0:19
• Each floating point representation has defined limits (including epsilon) based on the number of bits of exponent, mantissa, and how the signs are represented. Maybe you could give the exact form of the question. – Bill Barth Sep 8 '14 at 0:29
• @Rain: You should a) put that information in the question, and b) clearly state that your question is a homework question, because it's site policy. – Geoff Oxberry Sep 8 '14 at 23:26