| Trees | Indices | Help |
|---|
|
|
1 #!/usr/bin/env python
2 # -*-coding:utf-8 -*
3
4 # Pycalcar
5 # Copyright (C) 2013 GALODE A.
6 #
7 # This file is part of Pycalcar.
8 #
9 # Pycalcar is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # Pycalcar is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with Pycalcar. If not, see <http://www.gnu.org/licenses/>
21
22 """
23 :
24
25 G{importgraph Demo}
26 """
27
29 """
30 :
31
32 G{classtree}
33
34 DESCRIPTION
35 ===========
36 Allow to execute operations on money
37
38 FUNCTIONS
39 =========
40 f_convert_base
41 --------------
42 Convert a mount into base unit
43
44 f_convert_total
45 ---------------
46 Convert a base unit into different unit of a money
47
48 f_money_add
49 -----------
50 Make an add operation
51
52 f_money_sub
53 -----------
54 Make a substract operation
55
56 f_money_mult
57 ------------
58 Make a multiplion operation
59
60 f_money_div
61 -----------
62 Make a division operation
63 """
64
65
66 #===================================================#
67 # Init #
68 #===================================================#
71
72
73
74
75
76 #===================================================#
77 # Conversion en unite de base d'une devise #
78 #===================================================#
80 """
81 :
82
83 DESCRIPTION
84 ===========
85 Convert a mount into base unit
86
87 PARAMETERS
88 ==========
89 u0 => u9
90 --------
91 Mount in the different units of the money
92 tx0 => tx8
93 ----------
94 Rate between the different units of the money
95
96 RETURNS
97 =======
98 Mount in the base unit of the money
99 """
100 temp = u9 * tx8
101 base = u8 + temp
102 temp = base * tx7
103 base = u7 + temp
104 temp = base * tx6
105 base = u6 + temp
106 temp = base * tx5
107 base = u5 + temp
108 temp = base * tx4
109 base = u4 + temp
110 temp = base * tx3
111 base = u3 + temp
112 temp = base * tx2
113 base = u2 + temp
114 temp = base * tx1
115 base = u1 + temp
116 temp = base * tx0
117 base = u0 + temp
118
119 return base
120
121
122
123
124 #===================================================#
125 # Conversion en unite d'une devise depuis la base #
126 #===================================================#
128 """
129 :
130
131 DESCRIPTION
132 ===========
133 Convert a base unit into different unit of a money
134
135 PARAMETERS
136 ==========
137 base
138 ----
139 Mount in the base unit of the money
140 tx0 => tx8
141 ----------
142 Rate between the different units of the money
143
144 RETURNS
145 =======
146 Mount in the different units of the money
147 """
148 rate0 = tx0
149 rate1 = tx1 * rate0
150 rate2 = tx2 * rate1
151 rate3 = tx3 * rate2
152 rate4 = tx4 * rate3
153 rate5 = tx5 * rate4
154 rate6 = tx6 * rate5
155 rate7 = tx7 * rate6
156 rate8 = tx8 * rate7
157
158 u9 = u8 = u7 = u6 = u5 = u4 = u3 = u2 = u1 = u0 = 0
159
160 if base >= 0:
161 reste = base
162 else:
163 reste = -1 * base
164
165 if rate8 <> 0:
166 u9 = base / rate8
167 reste = reste - u9 * rate8
168 if rate7 <> 0:
169 u8 = reste / rate7
170 reste = reste - u8 * rate7
171 if rate6 <> 0:
172 u7 = reste / rate6
173 reste = reste - u7 * rate6
174 if rate5 <> 0:
175 u6 = reste / rate5
176 reste = reste - u6 * rate5
177 if rate4 <> 0:
178 u5 = reste / rate4
179 reste = reste - u5 * rate4
180 if rate3 <> 0:
181 u4 = reste / rate3
182 reste = reste - u4 * rate3
183 if rate2 <> 0:
184 u3 = reste / rate2
185 reste = reste - u3 * rate2
186 if rate1 <> 0:
187 u2 = reste / rate1
188 reste = reste - u2 * rate1
189 if rate0 <> 0:
190 u1 = reste / rate0
191 reste = reste - u1 * rate0
192 if base >=0:
193 u0 = reste
194 else:
195 u0 = -1 * reste
196
197 return u0,u1,u2,u3,u4,u5,u6,u7,u8,u9
198
199
200
201
202 #===================================================#
203 # Addition #
204 #===================================================#
205 - def f_money_add(self,u10,u11,u12,u13,u14,u15,u16,u17,u18,u19, \
206 u20,u21,u22,u23,u24,u25,u26,u27,u28,u29, \
207 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
208 """
209 :
210
211 DESCRIPTION
212 ===========
213 Make an add operation
214
215 PARAMETERS
216 ==========
217 u10 => u19
218 ----------
219 First line of operation, in the different units of the money
220 u20 => u29
221 ----------
222 Second line of operation, in the different units of the money
223 tx0 => tx8
224 ----------
225 Rate between the different units of the money
226
227 RETURNS
228 =======
229 Sum of the two lines in the different units of the money
230 """
231 mount1 = self.f_convert_base(u10, u11, u12, u13, u14, u15, u16, u17, u18, u19,\
232 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8)
233 mount2 = self.f_convert_base(u20, u21, u22, u23, u24, u25, u26, u27, u28, u29,\
234 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8)
235 result = mount1 + mount2
236
237 return self.f_convert_total(result, tx0, tx1, tx2, tx3, tx4, tx5, tx6, tx7, tx8)
238
239
240
241
242 #===================================================#
243 # Soustraction #
244 #===================================================#
245 - def f_money_sub(self,u10,u11,u12,u13,u14,u15,u16,u17,u18,u19, \
246 u20,u21,u22,u23,u24,u25,u26,u27,u28,u29, \
247 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
248 """
249 :
250
251 DESCRIPTION
252 ===========
253 Make a substract operation
254
255 PARAMETERS
256 ==========
257 u10 => u19
258 ----------
259 First line of operation, in the different units of the money
260 u20 => u29
261 ----------
262 Second line of operation, in the different units of the money
263 tx0 => tx8
264 ----------
265 Rate between the different units of the money
266
267 RETURNS
268 =======
269 Difference between first & second line, in the different units of the money
270 """
271 mount1 = self.f_convert_base(u10, u11, u12, u13, u14, u15, u16, u17, u18, u19,\
272 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8)
273 mount2 = self.f_convert_base(u20, u21, u22, u23, u24, u25, u26, u27, u28, u29,\
274 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8)
275 result = mount1 - mount2
276
277 return self.f_convert_total(result, tx0, tx1, tx2, tx3, tx4, tx5, tx6, tx7, tx8)
278
279
280
281
282 #===================================================#
283 # Multiplication #
284 #===================================================#
285 - def f_money_mult(self,mult,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
286 """
287 :
288
289 DESCRIPTION
290 ===========
291 Make a multiplion operation
292
293 PARAMETERS
294 ==========
295 mult
296 ----
297 Value of the multiplicator
298 u0 => u9
299 --------
300 Mount in the different units of the money
301 tx0 => tx8
302 ----------
303 Rate between the different units of the money
304
305 RETURNS
306 =======
307 Result of the multiplication operation, in the different units of the money
308 """
309 base = self.f_convert_base(u0, u1, u2, u3, u4, u5, u6, u7, u8, u9, \
310 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8)
311 result = base * mult
312
313 return self.f_convert_total(result, tx0, tx1, tx2, tx3, tx4, tx5, tx6, tx7, tx8)
314
315
316
317
318 #===================================================#
319 # Division #
320 #===================================================#
322 """
323 :
324
325 DESCRIPTION
326 ===========
327 Make a division operation
328
329 PARAMETERS
330 ==========
331 div
332 ---
333 Value of the divisor
334 u0 => u9
335 --------
336 Mount in the different units of the money
337 tx0 => tx8
338 ----------
339 Rate between the different units of the money
340
341 RETURNS
342 =======
343 Result of the division operation, in the different units of the money, & the rest of the division
344 """
345 base = self.f_convert_base(u0, u1, u2, u3, u4, u5, u6, u7, u8, u9, \
346 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8)
347 result = base // div #permet d'effectuer une division entiere
348 reste = base%div
349
350 return self.f_convert_total(result, tx0, tx1, tx2, tx3, tx4, tx5, tx6, tx7, tx8), reste
351
352
353 #===================================================#
354 # Main de la classe #
355 #===================================================#
356 if __name__ == '__main__':
357 None
358
| Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Wed Jul 24 09:25:07 2013 | http://epydoc.sourceforge.net |