Added 'Extra precision' to report.

parent d205c1c6
...@@ -9,3 +9,4 @@ report.pdf ...@@ -9,3 +9,4 @@ report.pdf
fd* fd*
pr pr
floating_point.tex floating_point.tex
extra_precision.tex
...@@ -6,7 +6,10 @@ OPS=ADD DIV MULT SQRT ...@@ -6,7 +6,10 @@ OPS=ADD DIV MULT SQRT
all: fp speed highlight report.pdf sum pr all: fp speed highlight report.pdf sum pr
highlight: floating_point.tex highlight: floating_point.tex extra_precision.tex
extra_precision.tex: extra_precision.c
pygmentize -O style=colorful -o $@ $^
floating_point.tex: floating_point.c floating_point.tex: floating_point.c
pygmentize -O style=colorful -o $@ $^ pygmentize -O style=colorful -o $@ $^
......
#include <stdio.h> #include <stdio.h>
// Calculate 'e' using // Calculate 'e' using e=1+1/1!+1/2!+1/3!+1/4!+...
// e=1+1/1!+1/2!+1/3!+1/4!+... // 8! is 8x7x6x5x4x3x2x1. The series converges rapidly to e.
// 4! is 4x3x2x1. The series converges rapidly to e.
// That series comes from this series: int fact(int x) { return x > 0 ? x * fact(x-1) : 1; }
// 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) { int main(void) {
float last_e, e; float last_e, e;
......
...@@ -153,6 +153,31 @@ Type & N & Forward & Backward \\ ...@@ -153,6 +153,31 @@ Type & N & Forward & Backward \\
% }}} % }}}
\section{Extra precision} % {{{
\label{sec:Extra precision}
Our machine has an Intel Core2 Duo cpu (cpu type is E6750) running at 2.66GHz.
Because Intel added the x87 instruction set (a subset of x86), the FPU
(floating point unit) has a more precise floating point register.
To demonstrate this, we created simple C program, which will approximate the
constant $e$ twice. The first time it will save the final result in a float, the
second time it will store the result in the floating point register. The second
approximation is compared to the first and if the first approximation is large
than the second, the processor has a more precise floating point register. The
simple C program is listed in the appendix \ref{sec:extra_precision.c} and
produces this output:
\begin{verbatim}
$ ./pr
more precision detected!
diff:
2.6910297870635986328125000000000000000000000000000000000
2.6910298253667153112189680541632696986198425292968750000
\end{verbatim}
% }}}
\appendix{} \appendix{}
\section{floating\_point.c} % {{{ \section{floating\_point.c} % {{{
...@@ -162,5 +187,12 @@ Type & N & Forward & Backward \\ ...@@ -162,5 +187,12 @@ Type & N & Forward & Backward \\
% }}} % }}}
\section{extra\_precision.c} % {{{
\label{sec:extra_precision.c}
\input{extra_precision}
% }}}
\end{document} \end{document}
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