-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversions.tex
95 lines (86 loc) · 2.29 KB
/
conversions.tex
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
% !TEX encoding = IsoLatin9
%%%%%%%%%%%%%%%%%%%%% SECTION 1
\section{Conversion automatique et "cast"}
\begin{frame}
\begin{columns}
\column{4.8cm}
\tableofcontents[currentsection,hideothersubsections]
\column{7cm}
\centering{
\includegraphics[width=7cm]{fig/conversion.jpg}
\hfill \textit{La conversion de Saint Paul} (vers 1690)\\
\hfill Luca Giordano (1634-1705)\\
\hfill Musée des Beaux-Arts de Nancy
}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\frametitle{Conversions implicites}
\begin{block}{}
Si une expression contient des opérandes de types différents (expressions mixtes),
des conversions se font automatiquement.
\end{block}
Hiérarchie :\\
\bvrb|int| $\rightarrow$ \bvrb|long| $\rightarrow$ \bvrb|float| $\rightarrow$ \bvrb|double|
\begin{codeblock}{}
\lstset{escapeinside={§§}}
%\lstset{basicstyle=\scriptsize}
\begin{codeC}
int a ; float x;
a*x ; // sera de type float
a*a + a*x // sera de type float
\end{codeC}
\end{codeblock}
\begin{alertblock}{}
Les conversions se font au fur et à mesure de l'évaluation, opération par opération
\end{alertblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Conversions explicites (cast)}
\begin{block}{}
Il est possible de forcer une conversion d'une expression quelconque
dans un type de son choix par la syntaxe :\\
\centering{
\bvrb|(£textitµtype§) £textitµoperande§ ;|\\
\bvrb|(£textitµtype§) £textitµexpression§ ;|\\
}
\end{block}
\begin{codeblock}{}
\lstset{escapeinside={§§}}
%\lstset{basicstyle=\scriptsize}
\begin{codeC}
float x = 5.2 ;
int a = 5 ;
(int) x ; // = 5
(float) a ; // = 5.0
(int) (x+a) ; // =10
\end{codeC}
\end{codeblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Remarques}
\begin{itemize}
\item Une division entre entiers est par défaut une division entière (euclidienne).
\begin{codeblock}{}
\lstset{escapeinside={§§}}
%\lstset{basicstyle=\scriptsize}
\begin{codeC}
float x ;
x = 3/2 ; //x = 1
x = ((float) a) / ((float) b) ; //x=1.5
\end{codeC}
\end{codeblock}
\pause
\item La conversion se fait avant l'affectation
\begin{codeblock}{}
\lstset{escapeinside={§§}}
%\lstset{basicstyle=\scriptsize}
\begin{codeC}
int a = 3 , b = 2 ; float x ;
x = a / b ; // x = 1.0
x = (float) (a/b) ; // x = 1.0
x= ((float a) / ((float) b) ; //x=1.5
\end{codeC}
\end{codeblock}
\end{itemize}
\end{frame}