Added 'extra precision' detection.

parent 82b84e36
......@@ -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++ ) {
float last_e, e;
int i, max_first = fact(8), max_last = fact(7);
e = 1;
for(int i = 1; i < 20; i++ ) {
e += 1.f / fact(i);
for(i = 1; i < max_first; i *= i+1 ) {
e += 1.f / i;
}
printf("approx. e: %.80f\n", e);
first = e;
last_e = e;
e = 1;
for(i = 1; i < max_last; i *= i+1 ) {
e += 1.f / i;
}
printf("diff: %.80f = (first - e)\n", first - e);
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;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment