/[hcalc]/source/type/reel_op.cpp
ViewVC logotype

Contents of /source/type/reel_op.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Fri Jun 6 16:49:35 2003 UTC (20 years, 10 months ago) by haypo
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +6 -0 lines
Utilisation des flux (ostringstream) pour les fonctions str_element
et str_expression, ce qui simplifie énormément le code et permet d'écrire
directement dans la console sans malloc/realloc).
Utilisation de la précompilation sous Borland C++ (ça booste carrément le
temps de compilation !).

1 /*
2 * Calculs sur les nombres réels avec vérification des erreurs de calcul :
3 * (underflow ou overflow). Utilise les registres du coprocesseur arithmétique
4 * Intel 387.
5 */
6
7 // Précompilation
8 #include "precomp.h"
9 #if defined(__BORLANDC__)
10 # pragma hdrstop
11 #endif
12
13 #include "entier_reel.h"
14 //---------------------------------------------------------------------------
15 #include "hfpu.h"
16 #include "herreur.h"
17 #include "config.h"
18
19 #if defined(UTILISE_FPU)
20 fexcept_t sauve_fpu;
21 # ifdef UTILISE_DENORMAL
22 # define TEST_EXCEPTION \
23 FE_OVERFLOW | FE_DIVBYZERO | FE_UNDERFLOW | FE_DENORMAL
24 # else
25 # define TEST_EXCEPTION \
26 FE_OVERFLOW | FE_DIVBYZERO | FE_UNDERFLOW
27 # endif
28 #endif
29
30 //---------------------------------------------------------------------------
31
32 #ifdef UTILISE_FPU
33 void ReelErreurTxt (const char *txt)
34 { ErreurCalcul ("Dépassement de la capacité des nombres réels (%s).", txt); }
35
36 void ReelErreurUnderflow(void) { ReelErreurTxt ("underflow"); }
37 void ReelErreurOverflow(void) { ReelErreurTxt ("overflow"); }
38 #ifdef UTILISE_DENORMAL
39 void ReelErreurDenormal(void) { ReelErreurTxt ("denormal"); }
40 #endif
41
42 void ReelErreurDivZero(void)
43 { ErreurCalcul ("Division par zéro lors d'un calcul sur des nombres réels."); }
44 #endif
45
46 //---------------------------------------------------------------------------
47
48 void AttrapeExceptionFPU()
49 {
50 #ifdef UTILISE_FPU
51 fegetexceptflag (&sauve_fpu, TEST_EXCEPTION);
52 feclearexcept (TEST_EXCEPTION);
53 #endif
54 }
55
56 //---------------------------------------------------------------------------
57
58 void TesteErreurFPU()
59 {
60 #ifdef UTILISE_FPU
61 if (fetestexcept(FE_UNDERFLOW)) ReelErreurUnderflow();
62 if (fetestexcept(FE_OVERFLOW)) ReelErreurOverflow();
63 if (fetestexcept(FE_DIVBYZERO)) ReelErreurDivZero();
64 #ifdef UTILISE_DENORMAL
65 if (fetestexcept(FE_DENORMAL)) ReelErreurDenormal();
66 #endif
67 #endif
68 }
69
70 //---------------------------------------------------------------------------
71
72 void RetablitExceptionFPU()
73 {
74 #ifdef UTILISE_FPU
75 fesetexceptflag (&sauve_fpu, TEST_EXCEPTION);
76 #endif
77 }
78
79 //---------------------------------------------------------------------------
80
81 Reel_t Somme_Reel (const Reel_t a, const Reel_t b)
82 {
83 Reel_t x;
84 AttrapeExceptionFPU();
85 x = a;
86 x += b;
87 TesteErreurFPU();
88 RetablitExceptionFPU();
89 return x;
90 }
91
92 //---------------------------------------------------------------------------
93
94 Reel_t Difference_Reel (const Reel_t a, const Reel_t b)
95 {
96 Reel_t x;
97 AttrapeExceptionFPU();
98 x = a;
99 x -= b;
100 TesteErreurFPU();
101 RetablitExceptionFPU();
102 return x;
103 }
104
105 //---------------------------------------------------------------------------
106
107 Reel_t Produit_Reel (const Reel_t a, const Reel_t b)
108 {
109 Reel_t x;
110 AttrapeExceptionFPU();
111 x = a;
112 x *= b;
113 TesteErreurFPU();
114 RetablitExceptionFPU();
115 return x;
116 }
117
118 //---------------------------------------------------------------------------
119
120 Reel_t Quotient_Reel (const Reel_t a, const Reel_t b)
121 {
122 Reel_t x;
123 AttrapeExceptionFPU();
124 x = a;
125 x /= b;
126 TesteErreurFPU();
127 RetablitExceptionFPU();
128 return x;
129 }
130
131 //---------------------------------------------------------------------------
132
133 Reel_t Puissance_Reel (const Reel_t a, const Reel_t b)
134 {
135 Reel x;
136 AttrapeExceptionFPU();
137 x = Pow (a, b);
138 TesteErreurFPU();
139 RetablitExceptionFPU();
140 return x.Lit();
141 }
142
143 //---------------------------------------------------------------------------
144

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26