HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to calculate machine epsilon

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
machineepsiloncalculatehow

Problem

In a binary system we know that the next floating point number after 4 is 4+1/32. What is the machine epsilon? Is it 1/32 and if yes, why?

Solution

First note that $eps$ is not necessarily the same on every machine, it depends on architecture and precision. Also, the definition of $eps$ is not unique in literature. Often it is defined as the difference between $1$ and the next greater number that can be represented exactly, sometimes it is half of this difference (as it is the maximal relative error). In general, if you look at a machine number with base $b$, mantissa $m$ (and exponent $e$), you can define $$eps := \frac{b^{1-m}}{2}.$$

To your example: You would probably represent $4$ normalized as $(0.10000000)_2 \cdot 2^3$. The next number $4+ \frac{1}{32}$ is then represented as $(0.10000001)_2 \cdot 2^3$, i.e. you have $m = 8$ and thus $eps = 2^{-8}$.

Context

StackExchange Computer Science Q#94033, answer score: 2

Revisions (0)

No revisions yet.