user1767754
user1767754

Reputation: 25164

How is machine epsilon calculated?

Machine Epsilon for 32-Bit Float ISO-C Standard is: 1.19209e-07 The max Float is: 3.40282e+38

How is the machine epsilon derived from float max?

I have used this snippet to get the values:

std::cout<<std::numeric_limits<float>::max()<<std::endl;
std::cout<<std::numeric_limits<float>::epsilon()<<std::endl;

Upvotes: 0

Views: 1425

Answers (1)

Pascal Cuoq
Pascal Cuoq

Reputation: 80355

How is the machine epsilon derived from float max?

You could derive the machine epsilon of an IEEE 754-like binary floating-point system from the maximum finite float by observing that, the maximum finite float is written 1.111<n binary digits one> * 2emax.

In these conditions, the machine epsilon is, in binary, 0.000<n-1 binary digits zero>1.

However, the maximum finite float and the machine epsilon are really different parameters that capture different characteristics of a floatin-point system: the range of values that can be represented with finite approximations, and the precision of these approximations.

EDIT: by request from the OP, a skeletal implementation:

#include <stdio.h>
#include <float.h>

int main(void) {
  printf("%a\n", FLT_MAX);
  printf("FLT_MAX is 0x1.fffffep+127 therefore machine epsilon must be:\n");
  printf("           0x0.000002p0 that is approx %e in decimal\n", 0x0.000002p0);
}

On my platform I get the result:

0x1.fffffep+127
FLT_MAX is 0x1.fffffep+127 therefore machine epsilon must be:
           0x0.000002p0 that is approx 1.192093e-07 in decimal

Since the entire exercise is utterly pointless, the actual computation of the machine epsilon from FLT_MAX is left as an exercise to the reader.

Upvotes: 2

Related Questions