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, Inc.
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/math/neg.h>
27
double Item_func_neg::real_op()
29
double value= args[0]->val_real();
30
null_value= args[0]->null_value;
35
int64_t Item_func_neg::int_op()
37
int64_t value= args[0]->val_int();
38
null_value= args[0]->null_value;
44
type::Decimal *Item_func_neg::decimal_op(type::Decimal *decimal_value)
46
type::Decimal val, *value= args[0]->val_decimal(&val);
47
if (!(null_value= args[0]->null_value))
49
class_decimal2decimal(value, decimal_value);
50
class_decimal_neg(decimal_value);
57
void Item_func_neg::fix_num_length_and_dec()
59
decimals= args[0]->decimals;
60
/* 1 add because sign can appear */
61
max_length= args[0]->max_length + 1;
65
void Item_func_neg::fix_length_and_dec()
67
Item_func_num1::fix_length_and_dec();
70
If this is in integer context keep the context as integer if possible
71
(This is how multiplication and other integer functions works)
72
Use val() to get value as arg_type doesn't mean that item is
73
Item_int or Item_real due to existence of Item_param.
75
if (hybrid_type == INT_RESULT && args[0]->const_item())
77
int64_t val= args[0]->val_int();
78
if ((uint64_t) val >= (uint64_t) INT64_MIN &&
79
((uint64_t) val != (uint64_t) INT64_MIN ||
80
args[0]->type() != INT_ITEM))
83
Ensure that result is converted to DECIMAL, as int64_t can't hold
86
hybrid_type= DECIMAL_RESULT;
92
} /* namespace drizzled */