1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
22
#include <drizzled/function/numhybrid.h>
24
void Item_func_numhybrid::fix_num_length_and_dec()
27
void Item_func_numhybrid::fix_length_and_dec()
29
fix_num_length_and_dec();
33
String *Item_func_numhybrid::val_str(String *str)
36
switch (hybrid_type) {
39
my_decimal decimal_value, *val;
40
if (!(val= decimal_op(&decimal_value)))
41
return 0; // null is set
42
my_decimal_round(E_DEC_FATAL_ERROR, val, decimals, false, val);
43
my_decimal2string(E_DEC_FATAL_ERROR, val, 0, 0, 0, str);
51
str->set_int(nr, unsigned_flag, &my_charset_bin);
59
str->set_real(nr,decimals,&my_charset_bin);
63
return str_op(&str_value);
71
double Item_func_numhybrid::val_real()
74
switch (hybrid_type) {
77
my_decimal decimal_value, *val;
79
if (!(val= decimal_op(&decimal_value)))
80
return 0.0; // null is set
81
my_decimal2double(E_DEC_FATAL_ERROR, val, &result);
86
int64_t result= int_op();
87
return unsigned_flag ? (double) ((uint64_t) result) : (double) result;
95
String *res= str_op(&str_value);
96
return (res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
97
&end_not_used, &err_not_used) : 0.0);
106
int64_t Item_func_numhybrid::val_int()
109
switch (hybrid_type) {
112
my_decimal decimal_value, *val;
113
if (!(val= decimal_op(&decimal_value)))
114
return 0; // null is set
116
my_decimal2int(E_DEC_FATAL_ERROR, val, unsigned_flag, &result);
122
return (int64_t) rint(real_op());
127
if (!(res= str_op(&str_value)))
130
char *end= (char*) res->ptr() + res->length();
131
const CHARSET_INFO * const cs= str_value.charset();
132
return (*(cs->cset->strtoll10))(cs, res->ptr(), &end, &err_not_used);
141
my_decimal *Item_func_numhybrid::val_decimal(my_decimal *decimal_value)
143
my_decimal *val= decimal_value;
145
switch (hybrid_type) {
147
val= decimal_op(decimal_value);
151
int64_t result= int_op();
152
int2my_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
157
double result= (double)real_op();
158
double2my_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
164
if (!(res= str_op(&str_value)))
167
str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(),
168
res->length(), res->charset(), decimal_value);