Skip to content

Instantly share code, notes, and snippets.

@moustachio-belvedere
Created August 18, 2019 18:47
Show Gist options
  • Save moustachio-belvedere/d9aeca8037a007c9ed6de1aaa804475b to your computer and use it in GitHub Desktop.
Save moustachio-belvedere/d9aeca8037a007c9ed6de1aaa804475b to your computer and use it in GitHub Desktop.
Corrected Floating Point machine epsilon calculation
#include <stdio.h>
int main(void)
{
float foo;
double bar;
foo = (float)((float)(7.0f/3.0f) - (float)(4.0f/3.0f) - 1.0f);
bar = (double)((double)(7.0/3.0) - (double)(4.0/3.0) - 1.0);
printf("\nM.E. for float: %e \n\n", foo);
printf("M.E. for double: %e \n\n", bar);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment