Commit 897a1d64 authored by Sander Mathijs van Veen's avatar Sander Mathijs van Veen

Merged makefile.

parents cadc6ad6 9e7fee90
sum.float
sum.double
sum
speed.*.* speed.*.*
speed speed
fp fp
......
CC=gcc CC=gcc
FLAGS=-Wall -Wextra -std=c99 -pedantic -O0 -lm FLAGS=-Wall -Wextra -std=c99 -pedantic -O0 -lm
TYPES=float double LD SPEED_TYPES=float double LD
SUM_TYPES=float double
OPS=ADD DIV MULT SQRT OPS=ADD DIV MULT SQRT
all: fp speed report.pdf fd pr all: fp speed report.pdf sum pr
%.pdf: %.tex %.pdf: %.tex
pdflatex $^ pdflatex $^
pdflatex $^ pdflatex $^
speed: speed.c speed: speed.c
for t in $(TYPES); do \ for t in $(SPEED_TYPES); do \
for o in $(OPS); do \ for o in $(OPS); do \
sed "s#{TYPE}#$$t#" $^ | sed "s#{OP}#$$o#" > speed.$$t.$$o.c; \ sed "s#{TYPE}#$$t#" $^ | sed "s#{OP}#$$o#" > speed.$$t.$$o.c; \
$(CC) $(FLAGS) -o speed.$$t.$$o speed.$$t.$$o.c; \ $(CC) $(FLAGS) -o speed.$$t.$$o speed.$$t.$$o.c; \
...@@ -25,11 +26,11 @@ pr: extra_precision.o ...@@ -25,11 +26,11 @@ pr: extra_precision.o
fp: floating_point.o fp: floating_point.o
$(CC) $(FLAGS) -o $@ $^ $(CC) $(FLAGS) -o $@ $^
fd: float_vs_double.c sum: sum.c
for t in float double; do \ for t in $(SUM_TYPES); do \
sed "s#{TYPE}#$$t#" $^ > fd.$$t.c; \ sed "s#{TYPE}#$$t#" $^ > sum.$$t.c; \
$(CC) $(FLAGS) -o fd.$$t fd.$$t.c; \ gcc $(FLAGS) -o sum.$$t sum.$$t.c; \
rm fd.$$t.c; \ rm sum.$$t.c; \
done; done;
touch $@ touch $@
...@@ -41,4 +42,4 @@ fd: float_vs_double.c ...@@ -41,4 +42,4 @@ fd: float_vs_double.c
clean: clean:
rm -vf *.o *.i *.s fp fd* speed speed.*.* floating_point \ rm -vf *.o *.i *.s fp fd* speed speed.*.* floating_point \
report.pdf *.aux *.log *.toc report.pdf *.aux *.log *.toc sum sum.float sum.double
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
{TYPE} sum_forward(int N);
{TYPE} sum_backward(int N);
int main(void) {
puts("Using type {TYPE}.");
puts("Forward summation:");
printf("N = 1e8: %e\n", sum_forward(1e8));
printf("N = 2e8: %e\n", sum_forward(2e8));
puts("Backward summation:");
printf("N = 1e8: %e\n", sum_backward(1e8));
printf("N = 2e8: %e\n", sum_backward(2e8));
return 0;
}
{TYPE} sum_forward(int N) { {TYPE} sum_forward(int N) {
{TYPE} sum = 0; {TYPE} sum = 0;
...@@ -36,3 +19,16 @@ int main(void) { ...@@ -36,3 +19,16 @@ int main(void) {
return sum; return sum;
} }
int main(void) {
puts("Using type {TYPE}.");
puts("Forward summation:");
printf("N = 1e8: %e\n", sum_forward(1e8));
printf("N = 2e8: %e\n", sum_forward(2e8));
puts("Backward summation:");
printf("N = 1e8: %e\n", sum_backward(1e8));
printf("N = 2e8: %e\n", sum_backward(2e8));
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