Added 'extra precision' (calculating 'e').

parent 2dbfe4db
...@@ -4,3 +4,4 @@ fp ...@@ -4,3 +4,4 @@ fp
float_double float_double
report.pdf report.pdf
fd* fd*
pr
...@@ -3,7 +3,7 @@ FLAGS=-Wall -Wextra -std=c99 -pedantic -O0 -lm ...@@ -3,7 +3,7 @@ FLAGS=-Wall -Wextra -std=c99 -pedantic -O0 -lm
TYPES=float double LD TYPES=float double LD
OPS=ADD DIV MULT SQRT OPS=ADD DIV MULT SQRT
all: fp speed report.pdf fd all: fp speed report.pdf fd pr
%.pdf: %.tex %.pdf: %.tex
pdflatex $^ pdflatex $^
...@@ -19,6 +19,9 @@ speed: speed.c ...@@ -19,6 +19,9 @@ speed: speed.c
done; done;
touch $@ touch $@
pr: extra_precision.o
$(CC) $(FLAGS) -o $@ $^
fp: floating_point.o fp: floating_point.o
$(CC) $(FLAGS) -o $@ $^ $(CC) $(FLAGS) -o $@ $^
......
#include <stdio.h>
// Calculate 'e' using
// e=1+1/1!+1/2!+1/3!+1/4!+...
// 4! is 4x3x2x1. The series converges rapidly to e.
// That series comes from this series:
// ex=1+x/1!+x2/2!+x3/3!+x4/4!+...
int fact(int x) {return x > 0 ? x * fact(x-1) : 1; }
int main(void) {
printf("fact 8: %d\n", fact(8));
float e = 1;
for(int i = 1; i < 20; i++ ) {
e += 1.f / fact(i);
}
printf("approx. e: %.80f\n", e);
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