Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
db6a27c2
Commit
db6a27c2
authored
Feb 09, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Kahan summation algorithm to question 3.
parent
d205c1c6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
14 deletions
+42
-14
simmod/ass1/.gitignore
simmod/ass1/.gitignore
+1
-0
simmod/ass1/Makefile
simmod/ass1/Makefile
+6
-3
simmod/ass1/kahan_sum.c
simmod/ass1/kahan_sum.c
+22
-0
simmod/ass1/report.tex
simmod/ass1/report.tex
+9
-7
simmod/ass1/sum.c
simmod/ass1/sum.c
+4
-4
No files found.
simmod/ass1/.gitignore
View file @
db6a27c2
...
...
@@ -9,3 +9,4 @@ report.pdf
fd*
pr
floating_point.tex
kahan
simmod/ass1/Makefile
View file @
db6a27c2
...
...
@@ -4,7 +4,7 @@ SPEED_TYPES=float double LD
SUM_TYPES
=
float double
OPS
=
ADD DIV MULT SQRT
all
:
fp speed highlight report.pdf sum pr
all
:
fp speed highlight report.pdf sum
kahan
pr
highlight
:
floating_point.tex
...
...
@@ -34,11 +34,14 @@ fp: floating_point.o
sum
:
sum.c
for
t
in
$(SUM_TYPES)
;
do
\
sed
"s#{TYPE}#
$$
t#"
$^
>
sum.
$$
t.c
;
\
gcc
$(FLAGS)
-o
sum.
$$
t sum.
$$
t.c
;
\
$(CC)
$(FLAGS)
-o
sum.
$$
t sum.
$$
t.c
;
\
rm
sum.
$$
t.c
;
\
done
;
touch
$@
kahan
:
kahan_sum.o
$(CC)
$(FLAGS)
-o
$@
$^
%.o
:
%.c
$(CC)
$(FLAGS)
-o
$@
-c
$^
...
...
@@ -47,4 +50,4 @@ sum: sum.c
clean
:
rm
-vf
*
.o
*
.i
*
.s fp
pr
fd
*
speed speed.
*
.
*
floating_point
\
report.pdf
*
.aux
*
.log
*
.toc
sum
sum.float sum.double
report.pdf
*
.aux
*
.log
*
.toc
sum
sum.float sum.double
kahan
simmod/ass1/kahan_sum.c
0 → 100644
View file @
db6a27c2
#include <stdlib.h>
#include <stdio.h>
float
kahan_sum
(
int
N
)
{
float
sum
=
0
.
0
,
c
=
0
.
0
,
t
,
y
;
for
(
int
i
=
1
;
i
<=
N
;
i
++
)
{
y
=
1
.
0
/
i
-
c
;
t
=
sum
+
y
;
c
=
(
t
-
sum
)
-
y
;
sum
=
t
;
}
return
sum
;
}
int
main
(
void
)
{
printf
(
"N = 1e8: %f
\n
"
,
kahan_sum
(
1e8
));
printf
(
"N = 2e8: %f
\n
"
,
kahan_sum
(
2e8
));
return
0
;
}
simmod/ass1/report.tex
View file @
db6a27c2
...
...
@@ -112,13 +112,13 @@ We've calculated $\sum_{i=1}^{N}\frac{1}{i}$ for $N = 10^8$ and $N = 2 \cdot
\texttt
{
float
}
and
\texttt
{
double
}
. The results of this are in the table below.
\begin{table}
[H]
\begin{tabular}
{
l|lll
}
Type
&
N
&
Forward
&
Backward
\\
\begin{tabular}
{
l|lll
l
}
Type
&
N
&
Forward
&
Backward
&
Kahan
\\
\hline
\texttt
{
float
}
&
$
10
^
8
$
&
$
15
.
40368
$
&
$
18
.
80792
$
\\
\texttt
{
float
}
&
$
2
\cdot
10
^
8
$
&
$
15
.
40368
$
&
$
18
.
80792
$
\\
\texttt
{
double
}
&
$
10
^
8
$
&
$
18
.
99790
$
&
$
18
.
99790
$
\\
\texttt
{
double
}
&
$
2
\cdot
10
^
8
$
&
$
19
.
69104
$
&
$
19
.
69104
$
\\
\texttt
{
float
}
&
$
10
^
8
$
&
$
15
.
40368
$
&
$
18
.
80792
$
&
$
18
.
99790
$
\\
\texttt
{
float
}
&
$
2
\cdot
10
^
8
$
&
$
15
.
40368
$
&
$
18
.
80792
$
&
$
19
.
69104
$
\\
\texttt
{
double
}
&
$
10
^
8
$
&
$
18
.
99790
$
&
$
18
.
99790
$
&
\\
\texttt
{
double
}
&
$
2
\cdot
10
^
8
$
&
$
19
.
69104
$
&
$
19
.
69104
$
&
\\
\end{tabular}
\caption
{
Results of various summation approaches on floats and doubles.
}
\end{table}
...
...
@@ -149,11 +149,13 @@ Type & N & Forward & Backward \\
to the same problem as described above: all numbers in
$
[
\frac
{
1
}{
10
^
8
}
,
\frac
{
1
}{
2
\cdot
10
^
8
}
]
$
are also represented as zero and therefore not added
to the result.
\item
To improve the precision of the
\texttt
{
float
}
data type summation, we
implemented the Kahan summation algorithm.
\end{itemize}
% }}}
\appendix
{}
\appendix
\section
{
floating
\_
point.c
}
% {{{
\label
{
sec:floating
_
point.c
}
...
...
simmod/ass1/sum.c
View file @
db6a27c2
...
...
@@ -23,12 +23,12 @@ 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
));
printf
(
"N = 1e8: %
f
\n
"
,
sum_forward
(
1e8
));
printf
(
"N = 2e8: %
f
\n
"
,
sum_forward
(
2e8
));
puts
(
"Backward summation:"
);
printf
(
"N = 1e8: %
e
\n
"
,
sum_backward
(
1e8
));
printf
(
"N = 2e8: %
e
\n
"
,
sum_backward
(
2e8
));
printf
(
"N = 1e8: %
f
\n
"
,
sum_backward
(
1e8
));
printf
(
"N = 2e8: %
f
\n
"
,
sum_backward
(
2e8
));
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment