1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
15 |
|
2234
by Brian Aker
Mass removal of ifdef/endif in favor of pragma once. |
16 |
#pragma once
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
17 |
#include <assert.h> |
18 |
#include <drizzled/sql_string.h> |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
19 |
#include <drizzled/definitions.h> |
20 |
#include <drizzled/type/time.h> |
|
2318.6.14
by Olaf van der Spek
Refactor |
21 |
|
22 |
namespace drizzled { |
|
575.1.11
by Monty Taylor
Coupla little fixes. |
23 |
|
1
by brian
clean slate |
24 |
typedef enum |
2069.2.5
by Brian Aker
Fix decimal from storage to timestamp. |
25 |
{
|
26 |
TRUNCATE= 0, |
|
27 |
HALF_EVEN, |
|
28 |
HALF_UP, |
|
29 |
CEILING, |
|
30 |
FLOOR
|
|
31 |
} decimal_round_mode; |
|
205
by Brian Aker
uint32 -> uin32_t |
32 |
typedef int32_t decimal_digit_t; |
1
by brian
clean slate |
33 |
|
2137.1.3
by Brian Aker
Move decimal_zero, and a light fix on the decimal_t type (ditch the |
34 |
struct decimal_t { |
1
by brian
clean slate |
35 |
int intg, frac, len; |
276
by Brian Aker
Cleaned out my_bool from strings. |
36 |
bool sign; |
1
by brian
clean slate |
37 |
decimal_digit_t *buf; |
2137.1.4
by Brian Aker
Merge in setup for decimal. |
38 |
|
39 |
/* set a decimal_t to zero */
|
|
40 |
inline void set_zero() |
|
41 |
{
|
|
42 |
buf[0]= 0; |
|
43 |
intg= 1; |
|
44 |
frac= 0; |
|
45 |
sign= 0; |
|
46 |
}
|
|
2137.1.5
by Brian Aker
Additional decimal. |
47 |
|
48 |
/* negate a decimal */
|
|
49 |
inline void negate() |
|
50 |
{
|
|
51 |
sign^=1; |
|
52 |
}
|
|
53 |
||
54 |
int isZero() const; |
|
55 |
||
2137.1.3
by Brian Aker
Move decimal_zero, and a light fix on the decimal_t type (ditch the |
56 |
};
|
1
by brian
clean slate |
57 |
|
287.3.10
by Monty Taylor
Const correctness change. |
58 |
int internal_str2dec(char *from, decimal_t *to, char **end, |
276
by Brian Aker
Cleaned out my_bool from strings. |
59 |
bool fixed); |
1241.3.1
by Trond Norbye
cleanup: const'd mystrings/decimal.h and use new style const in drizzled/my_decimal.h |
60 |
int decimal2string(const decimal_t *from, char *to, int *to_len, |
1
by brian
clean slate |
61 |
int fixed_precision, int fixed_decimals, |
62 |
char filler); |
|
1241.3.1
by Trond Norbye
cleanup: const'd mystrings/decimal.h and use new style const in drizzled/my_decimal.h |
63 |
int decimal2uint64_t(const decimal_t *from, uint64_t *to); |
64 |
int uint64_t2decimal(const uint64_t from, decimal_t *to); |
|
65 |
int decimal2int64_t(const decimal_t *from, int64_t *to); |
|
66 |
int int64_t2decimal(const int64_t from, decimal_t *to); |
|
67 |
int decimal2double(const decimal_t *from, double *to); |
|
68 |
int double2decimal(const double from, decimal_t *to); |
|
1
by brian
clean slate |
69 |
int decimal_actual_fraction(decimal_t *from); |
1241.3.1
by Trond Norbye
cleanup: const'd mystrings/decimal.h and use new style const in drizzled/my_decimal.h |
70 |
int decimal2bin(const decimal_t *from, unsigned char *to, int precision, int scale); |
481
by Brian Aker
Remove all of uchar. |
71 |
int bin2decimal(const unsigned char *from, decimal_t *to, int precision, int scale); |
1
by brian
clean slate |
72 |
|
73 |
int decimal_bin_size(int precision, int scale); |
|
74 |
||
1241.3.1
by Trond Norbye
cleanup: const'd mystrings/decimal.h and use new style const in drizzled/my_decimal.h |
75 |
int decimal_intg(const decimal_t *from); |
76 |
int decimal_add(const decimal_t *from1, const decimal_t *from2, decimal_t *to); |
|
77 |
int decimal_sub(const decimal_t *from1, const decimal_t *from2, decimal_t *to); |
|
78 |
int decimal_cmp(const decimal_t *from1, const decimal_t *from2); |
|
79 |
int decimal_mul(const decimal_t *from1, const decimal_t *from2, decimal_t *to); |
|
80 |
int decimal_div(const decimal_t *from1, const decimal_t *from2, decimal_t *to, |
|
1
by brian
clean slate |
81 |
int scale_incr); |
1241.3.1
by Trond Norbye
cleanup: const'd mystrings/decimal.h and use new style const in drizzled/my_decimal.h |
82 |
int decimal_mod(const decimal_t *from1, const decimal_t *from2, decimal_t *to); |
83 |
int decimal_round(const decimal_t *from, decimal_t *to, int new_scale, |
|
1
by brian
clean slate |
84 |
decimal_round_mode mode); |
85 |
void max_decimal(int precision, int frac, decimal_t *to); |
|
86 |
||
1883.4.1
by Gustaf Thorslund
Replaced macros with functions/templates. Part of blueprint: |
87 |
inline int string2decimal(char *from, decimal_t *to, char **end) |
88 |
{
|
|
89 |
return internal_str2dec(from, to, end, false); |
|
90 |
}
|
|
1
by brian
clean slate |
91 |
|
92 |
/*
|
|
93 |
returns the length of the buffer to hold string representation
|
|
94 |
of the decimal (including decimal dot, possible sign and \0)
|
|
95 |
*/
|
|
96 |
||
1883.4.1
by Gustaf Thorslund
Replaced macros with functions/templates. Part of blueprint: |
97 |
inline int decimal_string_size(const decimal_t *dec) |
98 |
{
|
|
99 |
return (dec->intg ? dec->intg : 1) + dec->frac + (dec->frac > 0) + 2; |
|
100 |
}
|
|
1
by brian
clean slate |
101 |
|
102 |
/*
|
|
103 |
conventions:
|
|
104 |
||
105 |
decimal_smth() == 0 -- everything's ok
|
|
106 |
decimal_smth() <= 1 -- result is usable, but precision loss is possible
|
|
107 |
decimal_smth() <= 2 -- result can be unusable, most significant digits
|
|
108 |
could've been lost
|
|
109 |
decimal_smth() > 2 -- no result was generated
|
|
110 |
*/
|
|
111 |
||
112 |
#define E_DEC_OK 0
|
|
113 |
#define E_DEC_TRUNCATED 1
|
|
114 |
#define E_DEC_OVERFLOW 2
|
|
115 |
#define E_DEC_DIV_ZERO 4
|
|
116 |
#define E_DEC_BAD_NUM 8
|
|
117 |
#define E_DEC_OOM 16
|
|
118 |
||
119 |
#define E_DEC_ERROR 31
|
|
120 |
#define E_DEC_FATAL_ERROR 30
|
|
2034.2.5
by Brian Aker
Improvement for decimal in encapsulation. |
121 |
|
122 |
||
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
123 |
#define DECIMAL_LONGLONG_DIGITS 22
|
124 |
||
125 |
/** maximum length of buffer in our big digits (uint32_t). */
|
|
126 |
#define DECIMAL_BUFF_LENGTH 9
|
|
127 |
||
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
128 |
/* the number of digits that type::Decimal can possibly contain */
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
129 |
#define DECIMAL_MAX_POSSIBLE_PRECISION (DECIMAL_BUFF_LENGTH * 9)
|
130 |
||
131 |
||
132 |
/**
|
|
133 |
maximum guaranteed precision of number in decimal digits (number of our
|
|
134 |
digits * number of decimal digits in one our big digit - number of decimal
|
|
135 |
digits in one our big digit decreased by 1 (because we always put decimal
|
|
136 |
point on the border of our big digits))
|
|
137 |
*/
|
|
138 |
#define DECIMAL_MAX_PRECISION (DECIMAL_MAX_POSSIBLE_PRECISION - 8*2)
|
|
139 |
#define DECIMAL_MAX_SCALE 30
|
|
140 |
#define DECIMAL_NOT_SPECIFIED 31
|
|
141 |
||
142 |
/**
|
|
143 |
maximum length of string representation (number of maximum decimal
|
|
144 |
digits + 1 position for sign + 1 position for decimal point)
|
|
145 |
*/
|
|
146 |
#define DECIMAL_MAX_STR_LENGTH (DECIMAL_MAX_POSSIBLE_PRECISION + 2)
|
|
147 |
||
2030.1.2
by Brian Aker
First pass in refactoring of the name of my_decimal. |
148 |
inline int class_decimal_int_part(uint32_t precision, uint32_t decimals) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
149 |
{
|
150 |
return precision - ((decimals == DECIMAL_NOT_SPECIFIED) ? 0 : decimals); |
|
151 |
}
|
|
152 |
||
153 |
int decimal_operation_results(int result); |
|
154 |
||
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
155 |
inline void max_Decimal(type::Decimal *to, int precision, int frac) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
156 |
{
|
157 |
assert((precision <= DECIMAL_MAX_PRECISION)&& |
|
158 |
(frac <= DECIMAL_MAX_SCALE)); |
|
159 |
max_decimal(precision, frac, (decimal_t*) to); |
|
160 |
}
|
|
161 |
||
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
162 |
inline void max_internal_decimal(type::Decimal *to) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
163 |
{
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
164 |
max_Decimal(to, DECIMAL_MAX_PRECISION, 0); |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
165 |
}
|
166 |
||
167 |
inline int check_result(uint32_t mask, int result) |
|
168 |
{
|
|
169 |
if (result & mask) |
|
170 |
decimal_operation_results(result); |
|
171 |
return result; |
|
172 |
}
|
|
173 |
||
2034.2.1
by Brian Aker
Move class_decimal2int to a method on Decimal. |
174 |
namespace type { |
175 |
/**
|
|
2069.2.5
by Brian Aker
Fix decimal from storage to timestamp. |
176 |
type Decimal class limits 'decimal_t' type to what we need in MySQL.
|
2034.2.1
by Brian Aker
Move class_decimal2int to a method on Decimal. |
177 |
|
178 |
It contains internally all necessary space needed by the instance so
|
|
179 |
no extra memory is needed. One should call fix_buffer_pointer() function
|
|
180 |
when he moves type::Decimal objects in memory.
|
|
181 |
*/
|
|
182 |
||
2069.2.5
by Brian Aker
Fix decimal from storage to timestamp. |
183 |
class Decimal : public decimal_t |
184 |
{
|
|
185 |
decimal_digit_t buffer[DECIMAL_BUFF_LENGTH]; |
|
186 |
||
187 |
public: |
|
188 |
||
189 |
void init() |
|
2034.2.1
by Brian Aker
Move class_decimal2int to a method on Decimal. |
190 |
{
|
2069.2.5
by Brian Aker
Fix decimal from storage to timestamp. |
191 |
len= DECIMAL_BUFF_LENGTH; |
192 |
buf= buffer; |
|
2034.2.1
by Brian Aker
Move class_decimal2int to a method on Decimal. |
193 |
#if !defined (HAVE_VALGRIND)
|
2069.2.5
by Brian Aker
Fix decimal from storage to timestamp. |
194 |
/* Set buffer to 'random' value to find wrong buffer usage */
|
195 |
for (uint32_t i= 0; i < DECIMAL_BUFF_LENGTH; i++) |
|
196 |
buffer[i]= i; |
|
2034.2.1
by Brian Aker
Move class_decimal2int to a method on Decimal. |
197 |
#endif
|
2069.2.5
by Brian Aker
Fix decimal from storage to timestamp. |
198 |
}
|
199 |
||
200 |
Decimal() |
|
201 |
{
|
|
202 |
init(); |
|
203 |
}
|
|
2137.1.3
by Brian Aker
Move decimal_zero, and a light fix on the decimal_t type (ditch the |
204 |
|
2069.2.5
by Brian Aker
Fix decimal from storage to timestamp. |
205 |
void fix_buffer_pointer() { buf= buffer; } |
206 |
bool sign() const { return decimal_t::sign; } |
|
207 |
void sign(bool s) { decimal_t::sign= s; } |
|
208 |
uint32_t precision() const { return intg + frac; } |
|
209 |
||
210 |
int val_int32(uint32_t mask, bool unsigned_flag, int64_t *l) const |
|
211 |
{
|
|
212 |
type::Decimal rounded; |
|
213 |
/* decimal_round can return only E_DEC_TRUNCATED */
|
|
214 |
decimal_round(static_cast<const decimal_t*>(this), &rounded, 0, HALF_UP); |
|
215 |
return check_result(mask, (unsigned_flag ? |
|
216 |
decimal2uint64_t(&rounded, reinterpret_cast<uint64_t *>(l)) : |
|
217 |
decimal2int64_t(&rounded, l))); |
|
218 |
}
|
|
219 |
||
220 |
int string_length() const |
|
221 |
{
|
|
222 |
return decimal_string_size(this); |
|
223 |
}
|
|
224 |
||
225 |
int val_binary(uint32_t mask, unsigned char *bin, int prec, int scale) const; |
|
226 |
||
2254
by Brian Aker
Shift CHARSET_INFO to charset_info_st |
227 |
int store(uint32_t mask, const char *from, uint32_t length, const charset_info_st * charset); |
2069.2.5
by Brian Aker
Fix decimal from storage to timestamp. |
228 |
|
229 |
int store(uint32_t mask, char *str, char **end) |
|
230 |
{
|
|
231 |
return check_result_and_overflow(mask, string2decimal(str, static_cast<decimal_t*>(this), end)); |
|
232 |
}
|
|
233 |
||
234 |
int store(uint32_t mask, const String *str) |
|
235 |
{
|
|
236 |
return store(mask, str->ptr(), str->length(), str->charset()); |
|
237 |
}
|
|
238 |
||
239 |
int check_result_and_overflow(uint32_t mask, int result) |
|
240 |
{
|
|
241 |
if (check_result(mask, result) & E_DEC_OVERFLOW) |
|
242 |
{
|
|
243 |
bool _sign= sign(); |
|
244 |
fix_buffer_pointer(); |
|
245 |
max_internal_decimal(this); |
|
246 |
sign(_sign); |
|
247 |
}
|
|
248 |
return result; |
|
249 |
}
|
|
250 |
||
251 |
void convert(double &value) const; |
|
252 |
};
|
|
2034.2.1
by Brian Aker
Move class_decimal2int to a method on Decimal. |
253 |
|
254 |
} // type |
|
255 |
||
256 |
std::ostream& operator<<(std::ostream& output, const type::Decimal &dec); |
|
257 |
||
2030.1.2
by Brian Aker
First pass in refactoring of the name of my_decimal. |
258 |
inline uint32_t class_decimal_length_to_precision(uint32_t length, uint32_t scale, |
2034.2.2
by Brian Aker
Add string_length() to Decimal class. |
259 |
bool unsigned_flag) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
260 |
{
|
261 |
return (uint32_t) (length - (scale>0 ? 1:0) - (unsigned_flag ? 0:1)); |
|
262 |
}
|
|
263 |
||
2030.1.2
by Brian Aker
First pass in refactoring of the name of my_decimal. |
264 |
inline uint32_t class_decimal_precision_to_length(uint32_t precision, uint8_t scale, |
2034.2.2
by Brian Aker
Add string_length() to Decimal class. |
265 |
bool unsigned_flag) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
266 |
{
|
267 |
set_if_smaller(precision, (uint32_t)DECIMAL_MAX_PRECISION); |
|
268 |
return static_cast<uint32_t>(precision + (scale>0 ? 1:0) + (unsigned_flag ? 0:1)); |
|
269 |
}
|
|
270 |
||
271 |
||
272 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
273 |
int class_decimal_max_length(const type::Decimal *d) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
274 |
{
|
275 |
/* -1 because we do not count \0 */
|
|
276 |
return decimal_string_size(d) - 1; |
|
277 |
}
|
|
278 |
||
279 |
||
280 |
inline
|
|
2030.1.2
by Brian Aker
First pass in refactoring of the name of my_decimal. |
281 |
int class_decimal_get_binary_size(uint32_t precision, uint32_t scale) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
282 |
{
|
283 |
return decimal_bin_size(static_cast<int>(precision), static_cast<int>(scale)); |
|
284 |
}
|
|
285 |
||
286 |
||
287 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
288 |
void class_decimal2decimal(const type::Decimal *from, type::Decimal *to) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
289 |
{
|
290 |
*to= *from; |
|
291 |
to->fix_buffer_pointer(); |
|
292 |
}
|
|
293 |
||
294 |
||
295 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
296 |
int binary2_class_decimal(uint32_t mask, const unsigned char *bin, type::Decimal *d, int prec, |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
297 |
int scale) |
298 |
{
|
|
299 |
return check_result(mask, bin2decimal(bin, static_cast<decimal_t*>(d), prec, scale)); |
|
300 |
}
|
|
301 |
||
302 |
||
303 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
304 |
int class_decimal_round(uint32_t mask, const type::Decimal *from, int scale, |
305 |
bool truncate, type::Decimal *to) |
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
306 |
{
|
307 |
return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, scale, |
|
308 |
(truncate ? TRUNCATE : HALF_UP))); |
|
309 |
}
|
|
310 |
||
311 |
||
312 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
313 |
int class_decimal_floor(uint32_t mask, const type::Decimal *from, type::Decimal *to) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
314 |
{
|
315 |
return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, 0, FLOOR)); |
|
316 |
}
|
|
317 |
||
318 |
||
319 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
320 |
int class_decimal_ceiling(uint32_t mask, const type::Decimal *from, type::Decimal *to) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
321 |
{
|
322 |
return check_result(mask, decimal_round(static_cast<const decimal_t*>(from), to, 0, CEILING)); |
|
323 |
}
|
|
324 |
||
325 |
||
2137.1.8
by Brian Aker
Remove error type from str convert since we always want an error. |
326 |
int class_decimal2string(const type::Decimal *d, |
2137.1.6
by Brian Aker
Remove ZEROFILL for decimal. |
327 |
uint32_t fixed_dec, String *str); |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
328 |
|
329 |
||
330 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
331 |
int class_decimal2double(uint32_t, const type::Decimal *d, double *result) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
332 |
{
|
333 |
/* No need to call check_result as this will always succeed */
|
|
334 |
return decimal2double(static_cast<const decimal_t*>(d), result); |
|
335 |
}
|
|
336 |
||
337 |
||
2030.1.5
by Brian Aker
Update for moving DRIZZLE_TIME to type::Time |
338 |
type::Decimal *date2_class_decimal(type::Time *ltime, type::Decimal *dec); |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
339 |
|
340 |
||
341 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
342 |
int double2_class_decimal(uint32_t mask, double val, type::Decimal *d) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
343 |
{
|
2034.2.5
by Brian Aker
Improvement for decimal in encapsulation. |
344 |
return d->check_result_and_overflow(mask, double2decimal(val, static_cast<decimal_t*>(d))); |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
345 |
}
|
346 |
||
347 |
||
348 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
349 |
int int2_class_decimal(uint32_t mask, int64_t i, bool unsigned_flag, type::Decimal *d) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
350 |
{
|
351 |
return check_result(mask, (unsigned_flag ? |
|
352 |
uint64_t2decimal(static_cast<uint64_t>(i), d) : |
|
353 |
int64_t2decimal(i, d))); |
|
354 |
}
|
|
355 |
||
356 |
||
357 |
inline
|
|
2030.1.2
by Brian Aker
First pass in refactoring of the name of my_decimal. |
358 |
void class_decimal_neg(decimal_t *arg) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
359 |
{
|
2137.1.5
by Brian Aker
Additional decimal. |
360 |
if (arg->isZero()) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
361 |
{
|
362 |
arg->sign= 0; |
|
363 |
return; |
|
364 |
}
|
|
2137.1.5
by Brian Aker
Additional decimal. |
365 |
arg->negate(); |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
366 |
}
|
367 |
||
368 |
||
369 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
370 |
int class_decimal_add(uint32_t mask, type::Decimal *res, const type::Decimal *a, |
371 |
const type::Decimal *b) |
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
372 |
{
|
2034.2.5
by Brian Aker
Improvement for decimal in encapsulation. |
373 |
return res->check_result_and_overflow(mask, |
374 |
decimal_add(static_cast<const decimal_t*>(a), |
|
375 |
static_cast<const decimal_t*>(b), res)); |
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
376 |
}
|
377 |
||
378 |
||
379 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
380 |
int class_decimal_sub(uint32_t mask, type::Decimal *res, const type::Decimal *a, |
381 |
const type::Decimal *b) |
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
382 |
{
|
2034.2.5
by Brian Aker
Improvement for decimal in encapsulation. |
383 |
return res->check_result_and_overflow(mask, |
384 |
decimal_sub(static_cast<const decimal_t*>(a), |
|
385 |
static_cast<const decimal_t*>(b), res)); |
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
386 |
}
|
387 |
||
388 |
||
389 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
390 |
int class_decimal_mul(uint32_t mask, type::Decimal *res, const type::Decimal *a, |
391 |
const type::Decimal *b) |
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
392 |
{
|
2034.2.5
by Brian Aker
Improvement for decimal in encapsulation. |
393 |
return res->check_result_and_overflow(mask, |
394 |
decimal_mul(static_cast<const decimal_t*>(a), |
|
395 |
static_cast<const decimal_t*>(b),res)); |
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
396 |
}
|
397 |
||
398 |
||
399 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
400 |
int class_decimal_div(uint32_t mask, type::Decimal *res, const type::Decimal *a, |
401 |
const type::Decimal *b, int div_scale_inc) |
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
402 |
{
|
2034.2.5
by Brian Aker
Improvement for decimal in encapsulation. |
403 |
return res->check_result_and_overflow(mask, |
404 |
decimal_div(static_cast<const decimal_t*>(a), |
|
405 |
static_cast<const decimal_t*>(b),res, |
|
406 |
div_scale_inc)); |
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
407 |
}
|
408 |
||
409 |
||
410 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
411 |
int class_decimal_mod(uint32_t mask, type::Decimal *res, const type::Decimal *a, |
412 |
const type::Decimal *b) |
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
413 |
{
|
2034.2.5
by Brian Aker
Improvement for decimal in encapsulation. |
414 |
return res->check_result_and_overflow(mask, |
415 |
decimal_mod(static_cast<const decimal_t*>(a), |
|
416 |
static_cast<const decimal_t*>(b),res)); |
|
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
417 |
}
|
418 |
||
419 |
||
420 |
/**
|
|
421 |
@return
|
|
422 |
-1 if a<b, 1 if a>b and 0 if a==b
|
|
423 |
*/
|
|
424 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
425 |
int class_decimal_cmp(const type::Decimal *a, const type::Decimal *b) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
426 |
{
|
427 |
return decimal_cmp(static_cast<const decimal_t*>(a), |
|
428 |
static_cast<const decimal_t*>(b)); |
|
429 |
}
|
|
430 |
||
431 |
||
432 |
inline
|
|
2030.1.4
by Brian Aker
Change my_decimal to Decimal |
433 |
int class_decimal_intg(const type::Decimal *a) |
1410.3.1
by Djellel E. Difallah
merge my_decimal and decimal |
434 |
{
|
435 |
return decimal_intg(static_cast<const decimal_t*>(a)); |
|
436 |
}
|
|
437 |
||
438 |
||
2030.1.2
by Brian Aker
First pass in refactoring of the name of my_decimal. |
439 |
void class_decimal_trim(uint32_t *precision, uint32_t *scale); |
1
by brian
clean slate |
440 |
|
2137.1.3
by Brian Aker
Move decimal_zero, and a light fix on the decimal_t type (ditch the |
441 |
inline type::Decimal &decimal_zero_const() |
442 |
{
|
|
443 |
static type::Decimal _decimal_zero; |
|
444 |
return _decimal_zero; |
|
445 |
}
|
|
446 |
||
2154.2.4
by Brian Aker
This fixes 716459 |
447 |
double my_double_round(double value, int64_t dec, bool dec_unsigned, |
448 |
bool truncate); |
|
449 |
||
450 |
||
2137.1.3
by Brian Aker
Move decimal_zero, and a light fix on the decimal_t type (ditch the |
451 |
#define decimal_zero decimal_zero_const()
|
452 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
453 |
} /* namespace drizzled */ |
575.1.11
by Monty Taylor
Coupla little fixes. |
454 |
|
1
by brian
clean slate |
455 |