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
20
#include <drizzled/server_includes.h>
22
#include <drizzled/functions/neg.h>
24
double Item_func_neg::real_op()
26
double value= args[0]->val_real();
27
null_value= args[0]->null_value;
32
int64_t Item_func_neg::int_op()
34
int64_t value= args[0]->val_int();
35
null_value= args[0]->null_value;
40
my_decimal *Item_func_neg::decimal_op(my_decimal *decimal_value)
42
my_decimal val, *value= args[0]->val_decimal(&val);
43
if (!(null_value= args[0]->null_value))
45
my_decimal2decimal(value, decimal_value);
46
my_decimal_neg(decimal_value);
53
void Item_func_neg::fix_num_length_and_dec()
55
decimals= args[0]->decimals;
56
/* 1 add because sign can appear */
57
max_length= args[0]->max_length + 1;
61
void Item_func_neg::fix_length_and_dec()
63
Item_func_num1::fix_length_and_dec();
66
If this is in integer context keep the context as integer if possible
67
(This is how multiplication and other integer functions works)
68
Use val() to get value as arg_type doesn't mean that item is
69
Item_int or Item_real due to existence of Item_param.
71
if (hybrid_type == INT_RESULT && args[0]->const_item())
73
int64_t val= args[0]->val_int();
74
if ((uint64_t) val >= (uint64_t) INT64_MIN &&
75
((uint64_t) val != (uint64_t) INT64_MIN ||
76
args[0]->type() != INT_ITEM))
79
Ensure that result is converted to DECIMAL, as int64_t can't hold
82
hybrid_type= DECIMAL_RESULT;