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

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

parent 2dbfe4db
No related branches found
No related tags found
No related merge requests found
......@@ -4,3 +4,4 @@ fp
float_double
report.pdf
fd*
pr
......@@ -3,7 +3,7 @@ FLAGS=-Wall -Wextra -std=c99 -pedantic -O0 -lm
TYPES=float double LD
OPS=ADD DIV MULT SQRT
all: fp speed report.pdf fd
all: fp speed report.pdf fd pr
%.pdf: %.tex
pdflatex $^
......@@ -19,6 +19,9 @@ speed: speed.c
done;
touch $@
pr: extra_precision.o
$(CC) $(FLAGS) -o $@ $^
fp: floating_point.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;
}
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