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
21
#include "drizzled/hybrid_type_traits_decimal.h"
22
#include "drizzled/hybrid_type.h"
23
#include "drizzled/definitions.h"
24
#include "drizzled/item.h"
32
/* Hybrid_type_traits_decimal */
33
static const Hybrid_type_traits_decimal decimal_traits_instance;
36
Item_result Hybrid_type_traits_decimal::type() const { return DECIMAL_RESULT; }
40
Hybrid_type_traits_decimal::fix_length_and_dec(Item *item, Item *arg) const
42
item->decimals= arg->decimals;
43
item->max_length= min(arg->max_length + DECIMAL_LONGLONG_DIGITS,
44
(unsigned int)DECIMAL_MAX_STR_LENGTH);
48
void Hybrid_type_traits_decimal::set_zero(Hybrid_type *val) const
50
my_decimal_set_zero(&val->dec_buf[0]);
51
val->used_dec_buf_no= 0;
55
void Hybrid_type_traits_decimal::add(Hybrid_type *val, Field *f) const
57
my_decimal_add(E_DEC_FATAL_ERROR,
58
&val->dec_buf[val->used_dec_buf_no ^ 1],
59
&val->dec_buf[val->used_dec_buf_no],
60
f->val_decimal(&val->dec_buf[2]));
61
val->used_dec_buf_no^= 1;
67
what is '4' for scale?
69
void Hybrid_type_traits_decimal::div(Hybrid_type *val, uint64_t u) const
71
int2my_decimal(E_DEC_FATAL_ERROR, u, true, &val->dec_buf[2]);
72
/* XXX: what is '4' for scale? */
73
my_decimal_div(E_DEC_FATAL_ERROR,
74
&val->dec_buf[val->used_dec_buf_no ^ 1],
75
&val->dec_buf[val->used_dec_buf_no],
77
val->used_dec_buf_no^= 1;
82
Hybrid_type_traits_decimal::val_int(Hybrid_type *val, bool unsigned_flag) const
85
my_decimal2int(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no],
86
unsigned_flag, &result);
92
Hybrid_type_traits_decimal::val_real(Hybrid_type *val) const
94
my_decimal2double(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no],
100
my_decimal *Hybrid_type_traits_decimal::val_decimal(Hybrid_type *val,
102
{ return &val->dec_buf[val->used_dec_buf_no]; }
106
Hybrid_type_traits_decimal::val_str(Hybrid_type *val, String *to,
107
uint8_t decimals) const
109
my_decimal_round(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no],
110
decimals, false, &val->dec_buf[2]);
111
my_decimal2string(E_DEC_FATAL_ERROR, &val->dec_buf[2], 0, 0, 0, to);
116
const Hybrid_type_traits_decimal *Hybrid_type_traits_decimal::instance()
118
return &decimal_traits_instance;
122
Hybrid_type_traits_decimal::Hybrid_type_traits_decimal()
125
} /* namespace drizzled */