1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

\section{Introduction}
Scilab take cares with your numbers.
While most mathematic books deals with exact formulas,
Scilab uses algorithms which are specifically designed for
computers.
The difficulty is generated by the fact that, while
the mathematics treat with \emph{real} numbers, the
computer deals with their \emph{floating point representations}.
This is the difference between the
\emph{naive}, mathematical, approach, and the \emph{numerical},
floatingpoint aware, implementation.
In this article, we will show examples of these problems by
using the following theoric and experimental approach.
\begin{enumerate}
\item First, we will derive the basic theory at the core of a numerical
formula.
\item Then we will implement it in Scilab and compare with the
result given by the primitive provided by Scilab.
As we will see, some particular cases do not work well
with our formula, while the Scilab primitive computes a correct
result.
\item Then we will analyse the \emph{reasons} of the differences.
\end{enumerate}
When we compute errors, we use the relative error formula
\begin{eqnarray}
e_r=\frac{x_cx_e}{x_e}, \qquad x_e\neq 0
\end{eqnarray}
where $x_c\in\RR$ is the computed value, and $x_e\in\RR$ is the
expected value, i.e. the mathematically exact result.
The relative error is linked with the number of significant
digits in the computed value $x_c$. For example, if the relative
error $e_r=10^{6}$, then the number of significant digits is 6.
When the expected value is zero, the relative error cannot
be computed, and we then use the absolute error
\begin{eqnarray}
e_a=x_cx_e.
\end{eqnarray}
A central reference on this subject is the article
by Goldberg, "What Every Computer Scientist Should Know About FloatingPoint Arithmetic",
\cite{WhatEveryComputerScientist}.
If one focuses on numerical algorithms, the "Numerical Recipes" \cite{NumericalRecipes},
is another good sources of solutions for that problem.
The work of Kahan is also central in this domain, for example \cite{Kahan2004}.
Before getting into the details, it is important to
know that real variables in the Scilab language are stored in
\emph{double precision} variables. Since Scilab is
following the IEEE 754 standard, that means that real
variables are stored with 64 bits precision.
As we shall see later, this has a strong influence on the
results.
