1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
38
35
assert(fixed == 1);
39
36
switch (hybrid_type) {
40
37
case DECIMAL_RESULT:
42
type::Decimal decimal_value, *val;
43
if (!(val= decimal_op(&decimal_value)))
44
return 0; // null is set
45
class_decimal_round(E_DEC_FATAL_ERROR, val, decimals, false, val);
46
class_decimal2string(val, 0, str);
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);
54
str->set_int(nr, unsigned_flag, &my_charset_bin);
51
str->set_int(nr, unsigned_flag, &my_charset_bin);
62
str->set_real(nr,decimals,&my_charset_bin);
59
str->set_real(nr,decimals,&my_charset_bin);
65
62
case STRING_RESULT:
66
63
return str_op(&str_value);
76
73
assert(fixed == 1);
77
74
switch (hybrid_type) {
78
75
case DECIMAL_RESULT:
80
type::Decimal decimal_value, *val;
82
if (!(val= decimal_op(&decimal_value)))
83
return 0.0; // null is set
84
class_decimal2double(E_DEC_FATAL_ERROR, val, &result);
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);
89
int64_t result= int_op();
90
return unsigned_flag ? (double) ((uint64_t) result) : (double) result;
86
int64_t result= int_op();
87
return unsigned_flag ? (double) ((uint64_t) result) : (double) result;
94
91
case STRING_RESULT:
98
String *res= str_op(&str_value);
99
return (res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
100
&end_not_used, &err_not_used) : 0.0);
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);
112
108
assert(fixed == 1);
113
109
switch (hybrid_type) {
114
110
case DECIMAL_RESULT:
116
type::Decimal decimal_value, *val;
117
if (!(val= decimal_op(&decimal_value)))
118
return 0; // null is set
120
val->val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
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);
125
121
case REAL_RESULT:
126
122
return (int64_t) rint(real_op());
127
123
case STRING_RESULT:
131
if (!(res= str_op(&str_value)))
127
if (!(res= str_op(&str_value)))
134
char *end= (char*) res->ptr() + res->length();
135
const CHARSET_INFO * const cs= str_value.charset();
136
return (*(cs->cset->strtoll10))(cs, res->ptr(), &end, &err_not_used);
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);
145
type::Decimal *Item_func_numhybrid::val_decimal(type::Decimal *decimal_value)
141
my_decimal *Item_func_numhybrid::val_decimal(my_decimal *decimal_value)
147
type::Decimal *val= decimal_value;
143
my_decimal *val= decimal_value;
148
144
assert(fixed == 1);
150
145
switch (hybrid_type) {
151
146
case DECIMAL_RESULT:
152
147
val= decimal_op(decimal_value);
156
int64_t result= int_op();
157
int2_class_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
151
int64_t result= int_op();
152
int2my_decimal(E_DEC_FATAL_ERROR, result, unsigned_flag, decimal_value);
160
155
case REAL_RESULT:
162
double result= (double)real_op();
163
double2_class_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
157
double result= (double)real_op();
158
double2my_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
166
161
case STRING_RESULT:
169
if (!(res= str_op(&str_value)))
164
if (!(res= str_op(&str_value)))
172
decimal_value->store(E_DEC_FATAL_ERROR, (char*) res->ptr(),
173
res->length(), res->charset());
167
str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(),
168
res->length(), res->charset(), decimal_value);
183
} /* namespace drizzled */