问题
This seems like a question better directed at those with some programming experience rather than just general Excel users, hence my asking on here as opposed to Superuser.
Is there any way, preferably through a function, to return epsilon (i.e. the smallest non-zero number representable in Excel's calculations)? If it's not retrievable through a function, is there a quick way to calculate it through a compact function?
To be clear, I'm not looking for a VBA-based solution, I'd like an Excel formula/ spreadsheet based solution that does not require running macros.
My searches online have mostly turned up discussions on how to display the symbol Epsilon.
Thanks.
回答1:
Excel always operates on IEEE doubles.
A non-VBA expression that will get you the smallest non-denormalized floating point number greater than 0 is
=2^-1022
Machine epsilon, on the other hand, is the smallest number that can be added to 1 and result in a number that is greater than 1. For double precision it is given by
=2^-52
回答2:
Microsoft defines its floating point number precision limits for XL. The smallest floating point number is listed as 2.2250738585072E-308 in the Microsoft support article ID: 78113. When I enter this number in my spreadsheet it actually stores a floating point 0, but if I store 2.2250738585073E-308, (I added 1 to the least significant digit) I can see all the digits. I see you asked for a machine epsilon, but since you are using XL, what you will really see is the C/C++ floating point library epsilon. See the Microsoft Developer Network xlfRegister (Form 1) topic.
回答3:
You may write a VBA subroutine like:
Public Sub ComputeMachineEpsilon()
Dim g, ex, eps As Double
Dim i As Long
g = 1
i = 0
Do
i = i + 1
g = g / 2
ex = g * 0.98 + 1
ex = ex - 1
If ex > 0 Then eps = ex
Loop While ex > 0
MsgBox ("No. of Iterations " & i)
MsgBox ("Machine Epsilon is " & eps)
End Sub
But on my machine it gives 2,22E-16, and it's strange because I can write =2^-113
in a cell and get 9,62965E-35.
EDIT:
=1*(0,5-0,4-0,1)
I get: -2,78E-17
来源:https://stackoverflow.com/questions/9380108/get-machine-epsilon-in-microsoft-excel