Skip to content

Epsilon

#include <math.h>
#include <stdio.h>

int main() {

  // Calculate epsilon
  float f_epsilon = 1.0f;
  while (1.0f + f_epsilon != 1.0f) {
    f_epsilon /= 2.0f; 
  }

  double d_epsilon = 1.0;
  while (1.0 + d_epsilon != 1.0) {
    d_epsilon /= 2.0;
  }

  long double ld_epsilon = 1.0L;
  while (1.0L + ld_epsilon != 1.0L) {
    ld_epsilon /= 2.0L;
  }

  // Print epsilons with max precision
  printf("Epsilon = %.20f\n", f_epsilon);
  printf("float epsilon = %.9e\n", f_epsilon);
  printf("double epsilon = %.17e\n", d_epsilon);
  printf("long double epsilon = %.33Le\n", ld_epsilon);
  
  return 0;
}
Published inUncategorized

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *