492.3.11
by Lee
code clean move Item_func_ceiling, Item_func_cos, Item_func_sin, Item_func_tan, Item_func_int_val to functions directory |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
20 |
#include <drizzled/server_includes.h> |
|
21 |
#include CSTDINT_H
|
|
642.1.30
by Lee
move math functions to drizzled/function/math directory |
22 |
#include <drizzled/function/math/int_val.h> |
492.3.11
by Lee
code clean move Item_func_ceiling, Item_func_cos, Item_func_sin, Item_func_tan, Item_func_int_val to functions directory |
23 |
|
24 |
void Item_func_int_val::fix_num_length_and_dec() |
|
25 |
{
|
|
26 |
max_length= args[0]->max_length - (args[0]->decimals ? |
|
27 |
args[0]->decimals + 1 : |
|
28 |
0) + 2; |
|
29 |
uint32_t tmp= float_length(decimals); |
|
30 |
set_if_smaller(max_length,tmp); |
|
31 |
decimals= 0; |
|
32 |
}
|
|
33 |
||
34 |
void Item_func_int_val::find_num_type() |
|
35 |
{
|
|
36 |
switch(hybrid_type= args[0]->result_type()) |
|
37 |
{
|
|
38 |
case STRING_RESULT: |
|
39 |
case REAL_RESULT: |
|
40 |
hybrid_type= REAL_RESULT; |
|
41 |
max_length= float_length(decimals); |
|
42 |
break; |
|
43 |
case INT_RESULT: |
|
44 |
case DECIMAL_RESULT: |
|
45 |
/*
|
|
46 |
-2 because in most high position can't be used any digit for int64_t
|
|
47 |
and one position for increasing value during operation
|
|
48 |
*/
|
|
49 |
if ((args[0]->max_length - args[0]->decimals) >= |
|
50 |
(DECIMAL_LONGLONG_DIGITS - 2)) |
|
51 |
{
|
|
52 |
hybrid_type= DECIMAL_RESULT; |
|
53 |
}
|
|
54 |
else
|
|
55 |
{
|
|
56 |
unsigned_flag= args[0]->unsigned_flag; |
|
57 |
hybrid_type= INT_RESULT; |
|
58 |
}
|
|
59 |
break; |
|
60 |
default: |
|
61 |
assert(0); |
|
62 |
}
|
|
63 |
return; |
|
64 |
}
|
|
65 |