Skip to content
Snippets Groups Projects
Commit 884ffe97 authored by Sander Mathijs van Veen's avatar Sander Mathijs van Veen
Browse files

Added 'extra precision' detection.

parent 82b84e36
No related branches found
No related tags found
No related merge requests found
......@@ -9,16 +9,25 @@
int fact(int x) {return x > 0 ? x * fact(x-1) : 1; }
int main(void) {
printf("fact 8: %d\n", fact(8));
float first, e;
for(int r = 0; r < 2; r++ ) {
e = 1;
for(int i = 1; i < 20; i++ ) {
e += 1.f / fact(i);
}
printf("approx. e: %.80f\n", e);
first = e;
float last_e, e;
int i, max_first = fact(8), max_last = fact(7);
e = 1;
for(i = 1; i < max_first; i *= i+1 ) {
e += 1.f / i;
}
printf("diff: %.80f = (first - e)\n", first - e);
last_e = e;
e = 1;
for(i = 1; i < max_last; i *= i+1 ) {
e += 1.f / i;
}
if( last_e < e + 1.f / (i*8) )
printf("more precision detected!\n");
printf("diff:\n%.80f\n%.80f \n", last_e, e + 1.f / (i*8));
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment