bzr branch
http://gegoxaren.bato24.eu/bzr/vqdr/trunk
19
by Gustav Hartvigsson
Added Round Up and Round Down function classes. |
1 |
/*
|
2 |
* The contects of this file is in the Public Domain.
|
|
3 |
*
|
|
4 |
* Created by Gustav Hartivgsson.
|
|
5 |
*/
|
|
27
by Gustav Hartvigsson
* Fixed Fastnumber's normalisation problem with the getters/setters |
6 |
using GLib; |
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
7 |
|
8 |
namespace Vee { |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
9 |
|
10 |
/** |
|
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
11 |
* Fast Numbers are a decimal representation of numbers in the form of
|
12 |
* a normal integer value. All internal numbers are multiples of 1000, so the
|
|
13 |
* there is room for two three decimal points.
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
14 |
*
|
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
15 |
* Maths done on these numbers are done using standard integer operations, and
|
16 |
* not floating point maths.
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
17 |
*
|
18 |
* The decimal part of the FastNumber has a maximum of 3 decimals.
|
|
27
by Gustav Hartvigsson
* Fixed Fastnumber's normalisation problem with the getters/setters |
19 |
*
|
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
20 |
* How the value is divided internally is as follows:
|
27
by Gustav Hartvigsson
* Fixed Fastnumber's normalisation problem with the getters/setters |
21 |
* {{{
|
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
22 |
* (base 10) [0 0 0 0 0 .... 0 | 0 0 0 ]
|
23 |
* [non-decial part | decimal]
|
|
27
by Gustav Hartvigsson
* Fixed Fastnumber's normalisation problem with the getters/setters |
24 |
* }}}
|
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
25 |
*
|
1
by Gustav Hartvigsson
* Initial code - far from done |
26 |
*/
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
27 |
|
28 |
public errordomain MathError { |
|
29 |
DIVIDE_BY_ZERO; |
|
30 |
} |
|
31 |
|
|
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
32 |
public struct FastNumber { |
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
33 |
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
34 |
|
19
by Gustav Hartvigsson
Added Round Up and Round Down function classes. |
35 |
/** Precision used to output values */ |
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
36 |
public const int32 PRECISION_DIGITS = 2; |
27
by Gustav Hartvigsson
* Fixed Fastnumber's normalisation problem with the getters/setters |
37 |
|
19
by Gustav Hartvigsson
Added Round Up and Round Down function classes. |
38 |
/** Precision factor used to evaluate output */ |
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
39 |
public const int32 PRECISION_FACTOR = 100; |
40 |
|
|
41 |
public const int32 MUL_FACTOR = PRECISION_FACTOR * 10; |
|
42 |
|
|
43 |
public int64 raw_number; |
|
44 |
|
|
45 |
public int64 leading_zeros; |
|
30
by Gustav Hartvigsson
EOF |
46 |
|
47 |
/* XXX |
|
48 |
* I'm not happy using getters/setters in this struct...
|
|
49 |
* But I tink it'll have to do for simplicity.
|
|
50 |
*/
|
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
51 |
public int64 number { |
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
52 |
public get {return (this.raw_number / MUL_FACTOR);} |
30
by Gustav Hartvigsson
EOF |
53 |
public set { |
54 |
this.raw_number = (MUL_FACTOR * value); |
|
27
by Gustav Hartvigsson
* Fixed Fastnumber's normalisation problem with the getters/setters |
55 |
} |
20
by Gustav Hartvigsson
* fixed the parsing of string in FastNumber.parse_raw_number () |
56 |
} |
57 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
58 |
/** |
59 |
* Initialises a FastNumber.
|
|
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
60 |
*
|
61 |
* Note: Due to implementation details, you can't pass a decimal part that
|
|
62 |
* is less than .1, as we are normalising decimal values to the
|
|
63 |
* correct place.
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
64 |
*
|
65 |
* @param number The number that are to be set as the none-decimal part of
|
|
66 |
* the number. Defaults to 0.
|
|
67 |
*
|
|
68 |
* @param decimal The decimal part of the number. Defaults to 0.
|
|
69 |
*/
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
70 |
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
71 |
public FastNumber (int64 number = 0) { |
30
by Gustav Hartvigsson
EOF |
72 |
if (number != 0) { |
73 |
this.raw_number = (number * MUL_FACTOR); |
|
74 |
} else { |
|
75 |
this.raw_number = 0; |
|
76 |
} |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
77 |
} |
78 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
79 |
/** |
80 |
* Do a deep copy of a FastNumber.
|
|
81 |
*/
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
82 |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
83 |
public FastNumber.copy (FastNumber other) { |
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
84 |
this.raw_number = other.raw_number; |
1
by Gustav Hartvigsson
* Initial code - far from done |
85 |
} |
86 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
87 |
/** |
88 |
* Initialises a FastNumber from a string.
|
|
89 |
*
|
|
90 |
* Can be a decimal representation.
|
|
91 |
*/
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
92 |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
93 |
public FastNumber.from_string (string str) { |
30
by Gustav Hartvigsson
EOF |
94 |
parse_raw_number (str); |
95 |
} |
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
96 |
/** |
97 |
* Initialises a FastNumber with the internal representation of that number.
|
|
98 |
*/
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
99 |
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
100 |
public FastNumber.raw (int64 raw) { |
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
101 |
this.raw_number = raw; |
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
102 |
} |
103 |
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
104 |
|
30
by Gustav Hartvigsson
EOF |
105 |
public FastNumber.from_float (double float_number) { |
106 |
// XXX Do we need a faster way of doing this? |
|
107 |
parse_raw_number (float_number.to_string ()); |
|
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
108 |
} |
109 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
110 |
/** |
111 |
* Add this to an other FastNumber.
|
|
112 |
*
|
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
113 |
* {{{
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
114 |
* var f1 = FastNumber (3); // f1 = 3
|
115 |
* var f2 = FastNumber (2); // f2 = 2
|
|
116 |
* var f3 = f1.add (f2); // f3 = 5
|
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
117 |
* }}}
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
118 |
*
|
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
119 |
* @return a newly initialised FastNumber.
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
120 |
*
|
121 |
* @param other The other fast number you want to add to this value.
|
|
122 |
*/
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
123 |
|
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
124 |
public FastNumber add (FastNumber? other) { |
125 |
if (other == null) { |
|
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
126 |
return FastNumber.copy (this); |
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
127 |
} |
128 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
129 |
var v = FastNumber (); |
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
130 |
v.raw_number = (this.raw_number + other.raw_number); |
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
131 |
return v; |
132 |
} |
|
133 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
134 |
/** |
135 |
* Add this to an other FastNumber.
|
|
136 |
*
|
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
137 |
* {{{
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
138 |
* var f1 = FastNumber (3); // f1 = 3
|
139 |
* var f2 = FastNumber (2); // f2 = 2
|
|
140 |
* var f3 = f1.subtract (f2); // f3 = 1
|
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
141 |
* }}}
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
142 |
*
|
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
143 |
* @return a newly initialised FastNumber.
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
144 |
*
|
145 |
* @param other The other fast number you want to subtract from this
|
|
146 |
* FastNumber.
|
|
147 |
*/
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
148 |
|
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
149 |
public FastNumber subtract (FastNumber? other) { |
150 |
if (other == null) { |
|
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
151 |
return FastNumber.copy (this); |
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
152 |
} |
153 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
154 |
var v = FastNumber (); |
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
155 |
v.raw_number = (this.raw_number - other.raw_number); |
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
156 |
return v; |
157 |
} |
|
158 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
159 |
/** |
160 |
* Multiply this FastNumber with another FastNumber.
|
|
161 |
*
|
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
162 |
* {{{
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
163 |
* var f1 = FastNumber (3); // f1 = 3
|
164 |
* var f2 = FastNumber (2); // f2 = 2
|
|
165 |
* var f3 = f1.multiply (f2); // f3 = 6
|
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
166 |
* }}}
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
167 |
*
|
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
168 |
* @return a newly initialised FastNumber.
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
169 |
*
|
170 |
* @param other The value you want to multiply this value with.
|
|
171 |
*/
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
172 |
|
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
173 |
public FastNumber multiply (FastNumber? other) { |
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
174 |
if (other == null || other.raw_number == 0 || this.raw_number == 0) { |
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
175 |
return FastNumber (); |
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
176 |
} |
177 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
178 |
var ret = FastNumber (); |
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
179 |
ret.raw_number = ((this.raw_number * other.raw_number) / MUL_FACTOR); |
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
180 |
return ret; |
181 |
} |
|
182 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
183 |
/** |
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
184 |
* Divide this FastNumbers with another FastNumber.
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
185 |
*
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
186 |
* {{{
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
187 |
* var f1 = FastNumber (6); // f1 = 6
|
188 |
* var f2 = FastNumber (2); // f2 = 2
|
|
189 |
* var f3 = f1.multiply (f2); // f3 = 3
|
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
190 |
* }}}
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
191 |
*
|
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
192 |
* @return a newly initialised FastNumber.
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
193 |
*
|
194 |
* @param other The value you want to multiply this value with.
|
|
195 |
*/
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
196 |
|
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
197 |
public FastNumber divide (FastNumber other) throws MathError { |
198 |
if (other.raw_number == 0) { |
|
27
by Gustav Hartvigsson
* Fixed Fastnumber's normalisation problem with the getters/setters |
199 |
throw new MathError.DIVIDE_BY_ZERO ("trying to divide by zero"); |
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
200 |
} |
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
201 |
var ret = FastNumber (); |
202 |
ret.raw_number = ((this.raw_number * MUL_FACTOR) / other.raw_number); |
|
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
203 |
return ret; |
204 |
} |
|
205 |
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
206 |
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
207 |
public int64 compare (FastNumber other) { |
12.1.2
by Gustav Hartvigsson
* Fastnumber is now a struct, |
208 |
return this.raw_number - other.raw_number; |
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
209 |
} |
210 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
211 |
/** |
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
212 |
* Round up this FastNumber and returns a new FastNumber.
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
213 |
*
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
214 |
* @return a rounded up FastNumber.
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
215 |
*/
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
216 |
|
19
by Gustav Hartvigsson
Added Round Up and Round Down function classes. |
217 |
public FastNumber round_up () { |
218 |
FastNumber ret; |
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
219 |
int64 decimal = raw_number % PRECISION_FACTOR; |
19
by Gustav Hartvigsson
Added Round Up and Round Down function classes. |
220 |
if (decimal > 0) { |
221 |
ret = FastNumber.raw (raw_number + PRECISION_FACTOR - decimal); |
|
222 |
} else { |
|
223 |
ret = FastNumber.raw (raw_number - decimal); |
|
224 |
} |
|
225 |
return ret; |
|
226 |
} |
|
227 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
228 |
/** |
29
by Gustav Hartvigsson
* Fixed documentation about FastNumber. |
229 |
* Round up this FastNumber and returns a new FastNumber.
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
230 |
*
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
231 |
* @return a rounded down FastNumber.
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
232 |
*/
|
19
by Gustav Hartvigsson
Added Round Up and Round Down function classes. |
233 |
public FastNumber round_down () { |
234 |
FastNumber ret; |
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
235 |
int64 decimal = raw_number % PRECISION_FACTOR; |
19
by Gustav Hartvigsson
Added Round Up and Round Down function classes. |
236 |
if (decimal < 0) { |
237 |
// Is this ever reached? |
|
238 |
ret = FastNumber.raw (raw_number - PRECISION_FACTOR - decimal); |
|
239 |
} else { |
|
240 |
ret = FastNumber.raw (raw_number - decimal); |
|
241 |
} |
|
242 |
return ret; |
|
243 |
} |
|
244 |
|
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
245 |
/** |
246 |
* FastNumber to string.
|
|
247 |
*
|
|
24
by Gustav Hartvigsson
* Fixed valadoc stuff. |
248 |
* @return a string
|
22
by Gustav Hartvigsson
* Added some documentation to the FastNumber class. |
249 |
*
|
250 |
* @param decimal whether to return the decimal portion of the number in
|
|
251 |
* the string. Default = false.
|
|
252 |
*/
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
253 |
|
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
254 |
public string to_string (bool decimal = false) { |
30
by Gustav Hartvigsson
EOF |
255 |
string ret_val = null; |
256 |
if (!decimal) { |
|
257 |
ret_val = (this.raw_number / MUL_FACTOR).to_string (); |
|
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
258 |
} else { |
30
by Gustav Hartvigsson
EOF |
259 |
// Copy stuff so we don't accidentality stomp them. |
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
260 |
int64 _raw_number = this.raw_number; |
30
by Gustav Hartvigsson
EOF |
261 |
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
262 |
int64 _integer_part = (_raw_number / MUL_FACTOR); |
263 |
int64 _decimal_part = (_raw_number - (_integer_part * MUL_FACTOR)); |
|
30
by Gustav Hartvigsson
EOF |
264 |
|
265 |
var strbldr = new GLib.StringBuilder (); |
|
266 |
|
|
267 |
// normalise the decimal part. |
|
268 |
// (XXX This is rather expensive, is there a better way of doing this?). |
|
269 |
if (_decimal_part != 0) { |
|
270 |
while ((_decimal_part % 10) == 0) { |
|
271 |
_decimal_part = _decimal_part / 10; |
|
272 |
} |
|
273 |
} |
|
274 |
|
|
275 |
strbldr.append (_integer_part.to_string ()) |
|
276 |
.append_c ('.'); |
|
277 |
|
|
278 |
|
|
279 |
for ( var i = this.leading_zeros ; i > 0 ; i--) { |
|
280 |
strbldr.append_c ('0'); |
|
281 |
} |
|
282 |
|
|
283 |
strbldr.append (_decimal_part.to_string ()); |
|
284 |
|
|
285 |
ret_val = strbldr.str; |
|
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
286 |
} |
30
by Gustav Hartvigsson
EOF |
287 |
return ret_val; |
288 |
} |
|
289 |
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
290 |
|
30
by Gustav Hartvigsson
EOF |
291 |
public double to_float () { |
292 |
// XXX This probobly needs to something faster? |
|
293 |
return double.parse (this.to_string (true)); |
|
294 |
} |
|
295 |
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
296 |
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
297 |
public int64 to_int () { |
30
by Gustav Hartvigsson
EOF |
298 |
return (this.raw_number / MUL_FACTOR); |
299 |
} |
|
12.1.1
by Gustav Hartvigsson
* Switch to using FastNumber instead of something else. |
300 |
|
27
by Gustav Hartvigsson
* Fixed Fastnumber's normalisation problem with the getters/setters |
301 |
/** |
302 |
* Check if two FastNumbers are equal.
|
|
303 |
*
|
|
304 |
* @return true if this is equal to the other.
|
|
305 |
* @return false if this is not equal to the other.
|
|
306 |
*/
|
|
307 |
public bool equals (FastNumber other) { |
|
308 |
return (this.raw_number == other.raw_number); |
|
309 |
} |
|
310 |
|
|
30
by Gustav Hartvigsson
EOF |
311 |
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
312 |
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
313 |
public static extern int64 static_compare (FastNumber a, FastNumber b); |
30
by Gustav Hartvigsson
EOF |
314 |
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
315 |
|
30
by Gustav Hartvigsson
EOF |
316 |
private void parse_raw_number (string str) { |
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
317 |
int64 ret_val = 0; |
1
by Gustav Hartvigsson
* Initial code - far from done |
318 |
int i_of_dot = str.index_of_char ('.'); |
319 |
if (i_of_dot >= 0) { |
|
320 |
// Get the decimal number from the string, if such a thing exists. |
|
321 |
if ((str.length - 1 > i_of_dot)) { |
|
30
by Gustav Hartvigsson
EOF |
322 |
var intr_str = (str + "000").substring (i_of_dot + 1); |
323 |
// count leading zeros. |
|
52.1.2
by Gustav Hartvigsson
no more 's |
324 |
// (Must be type long, as that is what string.substring () expects.) |
30
by Gustav Hartvigsson
EOF |
325 |
long i; |
326 |
for (i = 0; intr_str.@get (i) == '0'; i++){} |
|
327 |
this.leading_zeros = i; |
|
328 |
// remove leading zeros |
|
329 |
intr_str = intr_str.substring (i); |
|
66
by Gustav Hartvigsson
[libvee/fast_number.vala] Removed debug code. |
330 |
|
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
331 |
ret_val = int64.parse (intr_str); |
1
by Gustav Hartvigsson
* Initial code - far from done |
332 |
} |
333 |
|
|
334 |
// Normalise the digits. |
|
335 |
while (ret_val > MUL_FACTOR) { |
|
336 |
ret_val = ret_val / 10; |
|
337 |
} |
|
338 |
|
|
30
by Gustav Hartvigsson
EOF |
339 |
for (var i = leading_zeros; i > 0; i--) { |
340 |
ret_val = ret_val / 10; |
|
341 |
} |
|
342 |
|
|
20
by Gustav Hartvigsson
* fixed the parsing of string in FastNumber.parse_raw_number () |
343 |
|
30
by Gustav Hartvigsson
EOF |
344 |
// get integer number |
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
345 |
ret_val = ret_val + (int64.parse (str.substring (0, i_of_dot)) |
1
by Gustav Hartvigsson
* Initial code - far from done |
346 |
* MUL_FACTOR); |
20
by Gustav Hartvigsson
* fixed the parsing of string in FastNumber.parse_raw_number () |
347 |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
348 |
} else { |
52.1.1
by Gustav Hartvigsson
Use int64 instead of long. |
349 |
ret_val = (int64.parse (str) * MUL_FACTOR); |
30
by Gustav Hartvigsson
EOF |
350 |
} |
351 |
this.raw_number = ret_val; |
|
352 |
} |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
353 |
} |
354 |
}
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
355 |