Skip to content
Snippets Groups Projects
Commit edff8604 authored by Taddeüs Kroes's avatar Taddeüs Kroes
Browse files

Continued with question 3, not finished yet.

parent 0edc7329
No related branches found
No related tags found
No related merge requests found
speed.*.*
speed
fp
float_double
report.pdf
......@@ -2,7 +2,7 @@ FLAGS=-Wall -Wextra -std=c99 -pedantic -O0 -lm
TYPES=float double LD
OPS=ADD DIV MULT SQRT
all: fp speed report.pdf
all: fp speed report.pdf float_double
%.pdf: %.tex
pdflatex $^
......@@ -21,6 +21,9 @@ speed: speed.c
fp: floating_point.o
gcc $(FLAGS) -o $@ $^
float_double: float_vs_double.o
gcc $(FLAGS) -o $@ $^
%.o: %.c
gcc $(FLAGS) -o $@ -c $^
......
#include <stdlib.h>
#include <stdio.h>
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 = 0;
for( int i = 1; i <= N; i++ )
sum += 1.0 / i;
return sum;
}
{TYPE} sum_backward(int N) {
{TYPE} sum = 0;
for( int i = N; i; i-- )
sum += 1.0 / i;
return sum;
}
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